├── .gitignore
├── README.md
├── app.js
├── app.json
├── app.wxss
├── deps.edn
├── mini-program-cljs-example.png
├── npm_build.sh
├── open_cli_ws.sh
├── package.json
├── pages
├── index
│ ├── index.js
│ ├── index.json
│ ├── index.wxml
│ └── index.wxss
└── logs
│ ├── logs.js
│ ├── logs.json
│ ├── logs.wxml
│ └── logs.wxss
├── project.config.json
├── security_settings.png
├── shadow-cljs.edn
├── sitemap.json
├── src
└── mini_program_cljs_example
│ └── core.cljs
└── utils
└── util.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | miniprogram_npm/
4 | package-lock.json
5 | .shadow-cljs/
6 | .nrepl-port
7 | .cpcache/
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [mini-program-cljs(ClojureScript微信小程序库)](https://github.com/chanshunli/wechat-clj/tree/master/mini-program-cljs)开发者的示例项目和文档
2 |
3 | - [mini-program-cljs(ClojureScript微信小程序库)开发者的示例项目和文档](#mini-program-cljsclojurescript%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BA%93%E5%BC%80%E5%8F%91%E8%80%85%E7%9A%84%E7%A4%BA%E4%BE%8B%E9%A1%B9%E7%9B%AE%E5%92%8C%E6%96%87%E6%A1%A3)
4 | - [1. git clone本项目和wechat-clj下来到本地,第一次用微信开发者工具打开本项目(即导入本项目到开发者工具), 并打开安全设置, 然后完全关闭微信开发者工具(请确保进程关闭)](#1-git-clone%E6%9C%AC%E9%A1%B9%E7%9B%AE%E5%92%8Cwechat-clj%E4%B8%8B%E6%9D%A5%E5%88%B0%E6%9C%AC%E5%9C%B0%E7%AC%AC%E4%B8%80%E6%AC%A1%E7%94%A8%E5%BE%AE%E4%BF%A1%E5%BC%80%E5%8F%91%E8%80%85%E5%B7%A5%E5%85%B7%E6%89%93%E5%BC%80%E6%9C%AC%E9%A1%B9%E7%9B%AE%E5%8D%B3%E5%AF%BC%E5%85%A5%E6%9C%AC%E9%A1%B9%E7%9B%AE%E5%88%B0%E5%BC%80%E5%8F%91%E8%80%85%E5%B7%A5%E5%85%B7-%E5%B9%B6%E6%89%93%E5%BC%80%E5%AE%89%E5%85%A8%E8%AE%BE%E7%BD%AE-%E7%84%B6%E5%90%8E%E5%AE%8C%E5%85%A8%E5%85%B3%E9%97%AD%E5%BE%AE%E4%BF%A1%E5%BC%80%E5%8F%91%E8%80%85%E5%B7%A5%E5%85%B7%E8%AF%B7%E7%A1%AE%E4%BF%9D%E8%BF%9B%E7%A8%8B%E5%85%B3%E9%97%AD)
5 | - [2. 填入下面配置到deps.edn文件](#2-%E5%A1%AB%E5%85%A5%E4%B8%8B%E9%9D%A2%E9%85%8D%E7%BD%AE%E5%88%B0depsedn%E6%96%87%E4%BB%B6)
6 | - [3. 执行安装模拟器](#3-%E6%89%A7%E8%A1%8C%E5%AE%89%E8%A3%85%E6%A8%A1%E6%8B%9F%E5%99%A8)
7 | - [4. 启动开发者的模拟器](#4-%E5%90%AF%E5%8A%A8%E5%BC%80%E5%8F%91%E8%80%85%E7%9A%84%E6%A8%A1%E6%8B%9F%E5%99%A8)
8 | - [5. Emacs打开`src/mini_program_cljs_example/core.cljs`,并在该文件buffer下执行下面命令](#5-emacs%E6%89%93%E5%BC%80srcmini_program_cljs_examplecorecljs%E5%B9%B6%E5%9C%A8%E8%AF%A5%E6%96%87%E4%BB%B6buffer%E4%B8%8B%E6%89%A7%E8%A1%8C%E4%B8%8B%E9%9D%A2%E5%91%BD%E4%BB%A4)
9 | - [6. 启动Repl开发: `C-x C-e`执行`src/mini_program_cljs_example/core.cljs`中的代码,确认mini-program-cljs能正常连接到mini-program-cljs-example的repl来](#6-%E5%90%AF%E5%8A%A8repl%E5%BC%80%E5%8F%91-c-x-c-e%E6%89%A7%E8%A1%8Csrcmini_program_cljs_examplecorecljs%E4%B8%AD%E7%9A%84%E4%BB%A3%E7%A0%81%E7%A1%AE%E8%AE%A4mini-program-cljs%E8%83%BD%E6%AD%A3%E5%B8%B8%E8%BF%9E%E6%8E%A5%E5%88%B0mini-program-cljs-example%E7%9A%84repl%E6%9D%A5)
10 | - [evaluate-args 使用: 和微信开发者工具的控制台是完全联通的,但是不能用cljs.core方法在里面测试(因为goog导入不了)](#evaluate-args-%E4%BD%BF%E7%94%A8-%E5%92%8C%E5%BE%AE%E4%BF%A1%E5%BC%80%E5%8F%91%E8%80%85%E5%B7%A5%E5%85%B7%E7%9A%84%E6%8E%A7%E5%88%B6%E5%8F%B0%E6%98%AF%E5%AE%8C%E5%85%A8%E8%81%94%E9%80%9A%E7%9A%84%E4%BD%86%E6%98%AF%E4%B8%8D%E8%83%BD%E7%94%A8cljscore%E6%96%B9%E6%B3%95%E5%9C%A8%E9%87%8C%E9%9D%A2%E6%B5%8B%E8%AF%95%E5%9B%A0%E4%B8%BAgoog%E5%AF%BC%E5%85%A5%E4%B8%8D%E4%BA%86)
11 | - [基于S表达式Postwalk分离出来三种不同的代码执行环境: 关于evaluate-args(微信控制台环境) 和 wx.* 的环境 还有 current-page内部, 三者的开发环境的Repl开发打通方案](#%E5%9F%BA%E4%BA%8Es%E8%A1%A8%E8%BE%BE%E5%BC%8Fpostwalk%E5%88%86%E7%A6%BB%E5%87%BA%E6%9D%A5%E4%B8%89%E7%A7%8D%E4%B8%8D%E5%90%8C%E7%9A%84%E4%BB%A3%E7%A0%81%E6%89%A7%E8%A1%8C%E7%8E%AF%E5%A2%83-%E5%85%B3%E4%BA%8Eevaluate-args%E5%BE%AE%E4%BF%A1%E6%8E%A7%E5%88%B6%E5%8F%B0%E7%8E%AF%E5%A2%83-%E5%92%8C-wx-%E7%9A%84%E7%8E%AF%E5%A2%83-%E8%BF%98%E6%9C%89-current-page%E5%86%85%E9%83%A8-%E4%B8%89%E8%80%85%E7%9A%84%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E7%9A%84repl%E5%BC%80%E5%8F%91%E6%89%93%E9%80%9A%E6%96%B9%E6%A1%88)
12 |
13 | *本文档适用于: MacOS和Emacs开发者, Linux微信开发者工具基于Wine编译小程序速度太慢*
14 |
15 | [Youtube 演示视频](https://www.youtube.com/watch?v=Rmq3hCjdI6M)
16 |
17 | ### 1. git clone本项目和[wechat-clj](https://github.com/chanshunli/wechat-clj)下来到本地,第一次用微信开发者工具打开本项目(即导入本项目到开发者工具), 并打开安全设置, 然后完全关闭微信开发者工具(请确保进程关闭)
18 |
19 | 
20 |
21 | ### 2. 填入下面配置到deps.edn文件
22 |
23 | ```clojure
24 | ;; deps.edn 需要填入你本地的mini-program-cljs库的路径
25 | mini-program-cljs {:local/root "/Users/clojure/CljPro/wechat-clj/mini-program-cljs"}
26 |
27 | ```
28 |
29 | ### 3. 执行安装模拟器
30 |
31 | ``` shell
32 | # 需要填入mini-program-cljs-example的项目路径
33 | ./npm_build.sh ~/WeChatProjects/mini-program-cljs-example
34 |
35 | ```
36 |
37 | ### 4. 启动开发者的模拟器
38 |
39 | ``` shell
40 | # 需要填入mini-program-cljs-example的项目路径
41 | ./open_cli_ws.sh ~/WeChatProjects/mini-program-cljs-example
42 | ```
43 |
44 | ### 5. Emacs打开`src/mini_program_cljs_example/core.cljs`,并在该文件buffer下执行下面命令
45 |
46 | ``` shell
47 | M-x cider-jack-in-cljs => 选择 shadow-cljs => 选择 node-repl
48 |
49 | ;; 如需开发宏,在cljs的cider repl下执行:
50 | M-x cider-connect-sibling-clj
51 | ```
52 |
53 | ### 6. 启动Repl开发: `C-x C-e`执行`src/mini_program_cljs_example/core.cljs`中的代码,确认mini-program-cljs能正常连接到mini-program-cljs-example的repl来
54 |
55 | ``` clojure
56 |
57 | (ns mini-program-cljs-example.core
58 | (:require-macros
59 | [mini-program-cljs.macro
60 | :refer [call-promise-1 wx-fun-dev wx-fun evaluate-args c-log]])
61 | (:require
62 | ;; 开发mini-program-cljs库时需要引用miniprogram-automator模拟器
63 | [miniprogram-automator :as automator]
64 | [mini-program-cljs.core :as mini-cljs]
65 | [mini-program-cljs.js-wx :refer
66 | [mini-program current-page] :as jswx]))
67 |
68 | ;; 1. 初始化mini-program变量: 操作微信开发者工具的模拟器的变量mini-program
69 | (jswx/reset-mini-program automator)
70 |
71 | ;; 2. 初始化current-page变量: 当前微信小程序的页面
72 | (jswx/reset-current-page)
73 |
74 | ;; mini-program 成功获取的样子
75 | ;; => #object[cljs.core.Atom {:val #object[MiniProgram [object Object]]}]
76 |
77 | ;; current-page 成功获取的样子
78 | ;; => #object[cljs.core.Atom {:val #object[Page [object Object]]}]#object[cljs.core.Atom {:val #object[Page [object Object]]}];; => #object[cljs.core.Atom {:val #object[Page [object Object]]}]
79 |
80 | ;; 打印日志到微信开发者控制台
81 | (c-log @mini-program "aaaa" "bbb" "cccc"
82 | #js {:aaa 111 :bb "222dsadsa" :cc #js {:ooo 11 :bb "33"}})
83 |
84 | ;; 日志弹窗到页面
85 | (jswx/log #js {:aa 11} #js {:bb 22 :cc 33})
86 |
87 | ;; 万能的eval
88 | (evaluate-args @mini-program
89 | (fn [arg1 arg2] (js/console.log arg1 "," arg2))
90 | "Hi, " #js {:name "mini-program-cljs"})
91 |
92 | ```
93 |
94 | ### evaluate-args 使用: 和微信开发者工具的控制台是完全联通的,但是不能用cljs.core方法在里面测试(因为goog导入不了)
95 |
96 | * 传入cljs的函数作为参数进去会变成字符串,编译后的cljs代码的字符串
97 | * 传入js的函数,会变成native code的字符串
98 |
99 | ``` clojure
100 | (evaluate-args @mini-program
101 | (fn [arg]
102 | (js/console.log "---"
103 | (let [pages (js/getCurrentPages)
104 | len (.-length pages)
105 | current-page (aget pages (dec len))]
106 | current-page)
107 | )
108 | )
109 | #js [1 2 3])
110 | ;;=> 打印出来 page对象了
111 |
112 | (evaluate-args @mini-program
113 | (fn [arg]
114 | (js/console.log "---"
115 | (let [app (js/getApp)]
116 | (.-globalData app)
117 | )
118 | )
119 | )
120 | #js [])
121 | ;;=> 打印出来app.globalData
122 |
123 |
124 | ;;变量共享: 可以在控制台上看到这个变量
125 | (evaluate-args @mini-program
126 | (fn [arg1]
127 | (js/console.log "---"
128 | (set! js/aabb arg1)
129 | )
130 | )
131 | #js [1 2 3])
132 |
133 | ;; this使用: 下面代码会打印出来`window {...}`
134 | (evaluate-args @mini-program
135 | (fn [arg1]
136 | (js/console.log "---"
137 | (this-as this
138 | this)
139 | )
140 | )
141 | #js [])
142 |
143 | ```
144 |
145 | * 成功设置好的开发环境如下截图
146 |
147 | 
148 |
149 | ### 基于S表达式Postwalk分离出来三种不同的代码执行环境: 关于evaluate-args(微信控制台环境) 和 wx.* 的环境 还有 current-page内部, 三者的开发环境的Repl开发打通方案
150 |
151 | * 三个环境的混合wx,page内部,控制台, 通过错误分析来S表达式分开来分别执行后组合起来
152 | * evaluate-args内部没有cljs的执行环境,所以如果catch到cljs未定义的错误,那么就分离出来需要cljs的部分和不需要cljs的部分, 不需要cljs的部分执行结束后保存到中间变量里面, 将结果传递出来给cljs的代码处理
153 | * S表达式解析和Postwalk新的cljs解释器的构建,分离出来代码需要不同的执行环境,执行并且返回结果最终组合起来: repl一个本地环境模拟出来三种环境才是对的选择,解耦甚至可以脱离微信开发者工具你的开发的解释工具还能解释所有情况,那么这就是一个合格的开发环境了
154 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | // 展示本地存储能力
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 |
9 | // 登录
10 | wx.login({
11 | success: res => {
12 | // 发送 res.code 到后台换取 openId, sessionKey, unionId
13 | }
14 | })
15 | // 获取用户信息
16 | wx.getSetting({
17 | success: res => {
18 | if (res.authSetting['scope.userInfo']) {
19 | // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
20 | wx.getUserInfo({
21 | success: res => {
22 | // 可以将 res 发送给后台解码出 unionId
23 | this.globalData.userInfo = res.userInfo
24 |
25 | // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
26 | // 所以此处加入 callback 以防止这种情况
27 | if (this.userInfoReadyCallback) {
28 | this.userInfoReadyCallback(res)
29 | }
30 | }
31 | })
32 | }
33 | }
34 | })
35 | },
36 | globalData: {
37 | userInfo: null
38 | }
39 | })
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | "pages/index/index",
4 | "pages/logs/logs"
5 | ],
6 | "window": {
7 | "backgroundTextStyle": "light",
8 | "navigationBarBackgroundColor": "#fff",
9 | "navigationBarTitleText": "WeChat",
10 | "navigationBarTextStyle": "black"
11 | },
12 | "style": "v2",
13 | "sitemapLocation": "sitemap.json"
14 | }
--------------------------------------------------------------------------------
/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | .container {
3 | height: 100%;
4 | display: flex;
5 | flex-direction: column;
6 | align-items: center;
7 | justify-content: space-between;
8 | padding: 200rpx 0;
9 | box-sizing: border-box;
10 | }
11 |
--------------------------------------------------------------------------------
/deps.edn:
--------------------------------------------------------------------------------
1 | {:paths ["src"]
2 |
3 | :deps
4 | {org.clojure/clojure {:mvn/version "1.10.1"}
5 | org.clojure/clojurescript {:mvn/version "1.10.520"}
6 | mini-program-cljs {:local/root "/Users/clojure/CljPro/wechat-clj/mini-program-cljs"}}
7 |
8 | :aliases
9 | {:cljs
10 | {:extra-paths ["src"]
11 | :extra-deps {thheller/shadow-cljs {:mvn/version "2.8.83"}}}
12 |
13 | :shadow
14 | {:main-opts ["-m" "shadow.cljs.devtools.cli"]}}}
15 |
--------------------------------------------------------------------------------
/mini-program-cljs-example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xlisp/mini-program-cljs-example/2248da8b3e082ce1d6c2dcc09338f1fb7f5fdc07/mini-program-cljs-example.png
--------------------------------------------------------------------------------
/npm_build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | ## 更新npm后的,一键操作: `构建npm`
3 | npm i
4 | /Applications/wechatwebdevtools.app/Contents/MacOS/cli --build-npm $1
5 |
--------------------------------------------------------------------------------
/open_cli_ws.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Automator 模块提供了启动及连接开发者工具的方法: https://developers.weixin.qq.com/miniprogram/dev/devtools/auto/automator.html
3 | /Applications/wechatwebdevtools.app/Contents/MacOS/cli --auto $1 --auto-port 9420
4 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mini-program-cljs-example",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "app.js",
6 | "dependencies": {
7 | "mini-program-cljs": "^0.4.0"
8 | },
9 | "devDependencies": {
10 | "miniprogram-automator": "^0.9.1",
11 | "source-map-support": "^0.5.16"
12 | },
13 | "scripts": {
14 | "test": "echo \"Error: no test specified\" && exit 1"
15 | },
16 | "author": "",
17 | "license": "ISC"
18 | }
19 |
--------------------------------------------------------------------------------
/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | //获取应用实例
3 | const app = getApp()
4 |
5 | Page({
6 | data: {
7 | motto: 'Hello World',
8 | userInfo: {},
9 | hasUserInfo: false,
10 | canIUse: wx.canIUse('button.open-type.getUserInfo')
11 | },
12 | //事件处理函数
13 | bindViewTap: function() {
14 | wx.navigateTo({
15 | url: '../logs/logs'
16 | })
17 | },
18 | onLoad: function () {
19 | if (app.globalData.userInfo) {
20 | this.setData({
21 | userInfo: app.globalData.userInfo,
22 | hasUserInfo: true
23 | })
24 | } else if (this.data.canIUse){
25 | // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
26 | // 所以此处加入 callback 以防止这种情况
27 | app.userInfoReadyCallback = res => {
28 | this.setData({
29 | userInfo: res.userInfo,
30 | hasUserInfo: true
31 | })
32 | }
33 | } else {
34 | // 在没有 open-type=getUserInfo 版本的兼容处理
35 | wx.getUserInfo({
36 | success: res => {
37 | app.globalData.userInfo = res.userInfo
38 | this.setData({
39 | userInfo: res.userInfo,
40 | hasUserInfo: true
41 | })
42 | }
43 | })
44 | }
45 | },
46 | getUserInfo: function(e) {
47 | console.log(e)
48 | app.globalData.userInfo = e.detail.userInfo
49 | this.setData({
50 | userInfo: e.detail.userInfo,
51 | hasUserInfo: true
52 | })
53 | }
54 | })
55 |
--------------------------------------------------------------------------------
/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {
2 | "usingComponents": {}
3 | }
--------------------------------------------------------------------------------
/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | {{userInfo.nickName}}
8 |
9 |
10 |
11 | {{motto}}
12 |
13 |
14 |
--------------------------------------------------------------------------------
/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | .userinfo {
3 | display: flex;
4 | flex-direction: column;
5 | align-items: center;
6 | }
7 |
8 | .userinfo-avatar {
9 | width: 128rpx;
10 | height: 128rpx;
11 | margin: 20rpx;
12 | border-radius: 50%;
13 | }
14 |
15 | .userinfo-nickname {
16 | color: #aaa;
17 | }
18 |
19 | .usermotto {
20 | margin-top: 200px;
21 | }
--------------------------------------------------------------------------------
/pages/logs/logs.js:
--------------------------------------------------------------------------------
1 | //logs.js
2 | const util = require('../../utils/util.js')
3 |
4 | Page({
5 | data: {
6 | logs: []
7 | },
8 | onLoad: function () {
9 | this.setData({
10 | logs: (wx.getStorageSync('logs') || []).map(log => {
11 | return util.formatTime(new Date(log))
12 | })
13 | })
14 | }
15 | })
16 |
--------------------------------------------------------------------------------
/pages/logs/logs.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "查看启动日志",
3 | "usingComponents": {}
4 | }
--------------------------------------------------------------------------------
/pages/logs/logs.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{index + 1}}. {{log}}
5 |
6 |
7 |
--------------------------------------------------------------------------------
/pages/logs/logs.wxss:
--------------------------------------------------------------------------------
1 | .log-list {
2 | display: flex;
3 | flex-direction: column;
4 | padding: 40rpx;
5 | }
6 | .log-item {
7 | margin: 10rpx;
8 | }
9 |
--------------------------------------------------------------------------------
/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "项目配置文件",
3 | "packOptions": {
4 | "ignore": []
5 | },
6 | "setting": {
7 | "urlCheck": true,
8 | "es6": true,
9 | "postcss": true,
10 | "minified": true,
11 | "newFeature": true,
12 | "autoAudits": false,
13 | "coverView": true,
14 | "showShadowRootInWxmlPanel": true,
15 | "scopeDataCheck": false
16 | },
17 | "compileType": "miniprogram",
18 | "libVersion": "2.10.3",
19 | "appid": "wx2685c1da0abed116",
20 | "projectname": "mini-program-cljs-example",
21 | "debugOptions": {
22 | "hidedInDevtools": []
23 | },
24 | "isGameTourist": false,
25 | "simulatorType": "wechat",
26 | "simulatorPluginLibVersion": {},
27 | "condition": {
28 | "search": {
29 | "current": -1,
30 | "list": []
31 | },
32 | "conversation": {
33 | "current": -1,
34 | "list": []
35 | },
36 | "game": {
37 | "currentL": -1,
38 | "list": []
39 | },
40 | "miniprogram": {
41 | "current": -1,
42 | "list": []
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/security_settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xlisp/mini-program-cljs-example/2248da8b3e082ce1d6c2dcc09338f1fb7f5fdc07/security_settings.png
--------------------------------------------------------------------------------
/shadow-cljs.edn:
--------------------------------------------------------------------------------
1 | {:deps {:aliases [:cljs]}
2 | :source-paths ["src"]
3 |
4 | :dependencies []
5 |
6 | :builds {:app {:target :npm-module
7 | :output-dir "node_modules/clj-miniprogram"
8 | :entries []
9 | :compiler-options {:optimizations :advanced}}}}
10 |
--------------------------------------------------------------------------------
/sitemap.json:
--------------------------------------------------------------------------------
1 | {
2 | "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
3 | "rules": [{
4 | "action": "allow",
5 | "page": "*"
6 | }]
7 | }
--------------------------------------------------------------------------------
/src/mini_program_cljs_example/core.cljs:
--------------------------------------------------------------------------------
1 | (ns mini-program-cljs-example.core
2 | (:require-macros
3 | [mini-program-cljs.macro
4 | :refer [call-promise-1 wx-fun-dev wx-fun evaluate-args c-log]])
5 | (:require
6 | ;; 开发mini-program-cljs库时需要引用miniprogram-automator模拟器
7 | [miniprogram-automator :as automator]
8 | [mini-program-cljs.core :as mini-cljs]
9 | [mini-program-cljs.js-wx :refer
10 | [mini-program current-page] :as jswx]))
11 |
12 | ;; 1. 初始化mini-program变量: 操作微信开发者工具的模拟器的变量mini-program
13 | (jswx/reset-mini-program automator)
14 |
15 | ;; 2. 初始化current-page变量: 当前微信小程序的页面
16 | (jswx/reset-current-page)
17 |
18 | ;; mini-program 成功获取的样子
19 | ;; => #object[cljs.core.Atom {:val #object[MiniProgram [object Object]]}]
20 |
21 | ;; current-page 成功获取的样子
22 | ;; => #object[cljs.core.Atom {:val #object[Page [object Object]]}]#object[cljs.core.Atom {:val #object[Page [object Object]]}];; => #object[cljs.core.Atom {:val #object[Page [object Object]]}]
23 |
24 | ;; 打印日志到微信开发者控制台
25 | (c-log @mini-program "aaaa" "bbb" "cccc"
26 | #js {:aaa 111 :bb "222dsadsa" :cc #js {:ooo 11 :bb "33"}})
27 |
28 | ;; 日志弹窗到页面
29 | (jswx/log "Hi, " #js {:name "mini-program-cljs"})
30 |
31 | ;; 万能的eval
32 | (evaluate-args @mini-program
33 | (fn [arg1 arg2] (js/console.log arg1 "," arg2))
34 | "Hi, " #js {:name "mini-program-cljs"})
35 |
--------------------------------------------------------------------------------
/utils/util.js:
--------------------------------------------------------------------------------
1 | const formatTime = date => {
2 | const year = date.getFullYear()
3 | const month = date.getMonth() + 1
4 | const day = date.getDate()
5 | const hour = date.getHours()
6 | const minute = date.getMinutes()
7 | const second = date.getSeconds()
8 |
9 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
10 | }
11 |
12 | const formatNumber = n => {
13 | n = n.toString()
14 | return n[1] ? n : '0' + n
15 | }
16 |
17 | module.exports = {
18 | formatTime: formatTime
19 | }
20 |
--------------------------------------------------------------------------------