Skip to content

Commit 7ff8040

Browse files
committed
first commit
0 parents  commit 7ff8040

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+19984
-0
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
22+

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/miniprogram.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Website
2+
3+
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
4+
5+
### Installation
6+
7+
```
8+
$ yarn
9+
```
10+
11+
### Local Development
12+
13+
```
14+
$ yarn start
15+
```
16+
17+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18+
19+
### Build
20+
21+
```
22+
$ yarn build
23+
```
24+
25+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26+
27+
### Deployment
28+
29+
Using SSH:
30+
31+
```
32+
$ USE_SSH=true yarn deploy
33+
```
34+
35+
Not using SSH:
36+
37+
```
38+
$ GIT_USER=<Your GitHub username> yarn deploy
39+
```
40+
41+
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.

docs/cookbook/README.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
lang: zh-cmn-Hans-CN
3+
title: Cookbook
4+
---
5+
6+
# Cookbook
7+
8+
## 计算属性和侦听器
9+
10+
如果代码中,存在依赖响应式状态的复杂逻辑,可以使用 **计算属性(computed)****侦听器(watch)** 简化代码。
11+
12+
由于小程序本身不带计算属性(computed)和侦听器(watch)功能,需要通过 `miniprogram-computed` 引入相关的 behaviors,提供框架扩展支持。
13+
14+
```js{1,5,12-19,21-28}
15+
import { behavior as computedBehavior } from 'miniprogram-computed';
16+
import otherBehavior from './behavior/otherBehavior';
17+
18+
Component({
19+
behaviors: [otherBehavior, computedBehavior],
20+
data: {
21+
a: 1,
22+
b: 1,
23+
pow: 0,
24+
},
25+
26+
// 计算属性
27+
computed: {
28+
sum(data) {
29+
// 注意: computed 函数中不能访问 this ,只有 data 对象可供访问
30+
// 这个函数的返回值会被设置到 this.data.sum 字段中
31+
return data.a + data.b + data.c // data.c 为自定义 behavior 数据段
32+
},
33+
},
34+
35+
// 侦听器
36+
watch: {
37+
'a, b': function (a, b) {
38+
this.setData({
39+
pow: a ** b,
40+
})
41+
},
42+
},
43+
44+
methods: {
45+
onTap() {
46+
this.setData({
47+
a: this.data.b,
48+
b: this.data.a + this.data.b,
49+
});
50+
},
51+
},
52+
});
53+
```
54+
55+
## Lodash 的使用
56+
57+
[Lodash](https://lodash.com/) 是一个 JS 工具库,可以在微信小程序中使用。
58+
59+
使用 Lodash 时,由于小程序不提供全局环境,需要手动 polyfill。
60+
61+
```js
62+
// utlis/lodash-miniprogram-polyfill.js
63+
64+
global.Object = Object;
65+
global.Array = Array;
66+
global.DataView = DataView;
67+
global.Date = Date;
68+
global.Error = Error;
69+
global.Float32Array = Float32Array;
70+
global.Float64Array = Float64Array;
71+
global.Function = Function;
72+
global.Int8Array = Int8Array;
73+
global.Int16Array = Int16Array;
74+
global.Int32Array = Int32Array;
75+
global.Map = Map;
76+
global.Math = Math;
77+
global.Promise = Promise;
78+
global.RegExp = RegExp;
79+
global.Set = Set;
80+
global.String = String;
81+
global.Symbol = Symbol;
82+
global.TypeError = TypeError;
83+
global.Uint8Array = Uint8Array;
84+
global.Uint8ClampedArray = Uint8ClampedArray;
85+
global.Uint16Array = Uint16Array;
86+
global.Uint32Array = Uint32Array;
87+
global.WeakMap = WeakMap;
88+
global.clearTimeout = clearTimeout;
89+
/* eslint-disable-next-line no-restricted-properties */
90+
global.isFinite = Number.isFinite;
91+
global.parseInt = parseInt;
92+
global.setTimeout = setTimeout;
93+
```
94+
95+
由于完整版的 Lodash 包非常大(构建后大概 400KB),并且微信小程序不支持 Tree-Shaking,因此不要使用全量版本的 Lodash
96+
97+
**使用 Lodash 的[独立方法包](https://lodash.com/per-method-packages)**,可以有效减少包的体积。
98+
99+
:::danger 反面例子 👎
100+
缺少必要的 polyfill
101+
102+
```js
103+
import throttle from 'lodash.throttle';
104+
```
105+
106+
使用全量的 lodash 包
107+
108+
```js
109+
import './utils/lodash-miniprogram-polyfill';
110+
import { throttle } from 'lodash';
111+
```
112+
:::
113+
114+
:::tip 正面例子 👍
115+
```js
116+
import './utils/lodash-miniprogram-polyfill';
117+
import throttle from 'lodash.throttle';
118+
```
119+
:::
120+
121+
注意,在使用中,有部分方法不能使用箭头函数,否则会改变 `this` 的指向
122+
123+
:::danger 反面例子 👎
124+
使用箭头函数,会改变 `this` 的指向。
125+
126+
```js
127+
import './utils/lodash-miniprogram-polyfill';
128+
import throttle from 'lodash.throttle';
129+
130+
Page({
131+
onChange: throttle(() => {
132+
// ...
133+
}, 300),
134+
});
135+
```
136+
:::
137+
138+
:::tip 正面例子 👍
139+
使用 `function` 函数,不会改变 `this` 的指向。
140+
141+
```js
142+
import './utils/lodash-miniprogram-polyfill';
143+
import throttle from 'lodash.throttle';
144+
145+
Page({
146+
onChange: throttle(function () {
147+
// ...
148+
}, 300),
149+
});
150+
```
151+
:::
152+
153+
154+

docs/deploy/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
lang: zh-cmn-Hans-CN
3+
title: 部署
4+
---
5+
6+
# 部署
7+
8+
:::tip
9+
小程序的上传和发布推荐使用 [MiniProgram CI](https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html)
10+
:::
11+
12+
## 命令行配置
13+
14+
```json
15+
{
16+
"scripts": {
17+
"build": "node scripts/build.js",
18+
"deploy": "node scripts/deploy.js"
19+
},
20+
"devDependencies": {
21+
"miniprogram-ci": "^1.8.35"
22+
}
23+
}
24+
```
25+
26+
```bash
27+
# 构建 npm
28+
npm run build
29+
30+
# 上传代码
31+
npm run deploy
32+
```
33+
34+
## 构建 npm
35+
36+
```js
37+
// scripts/build.js
38+
39+
const path = require('path');
40+
const ci = require('miniprogram-ci');
41+
42+
(async () => {
43+
const packResult = await ci.packNpmManually({
44+
packageJsonPath: path.join(__dirname, '../package.json'),
45+
miniprogramNpmDistDir: path.join(__dirname, '../src/'),
46+
ignores: [],
47+
});
48+
49+
console.log('pack done, packResult:', packResult);
50+
})();
51+
```
52+
53+
## 上传代码
54+
55+
```js
56+
// scripts/deploy.js
57+
58+
const path = require('path');
59+
const ci = require('miniprogram-ci');
60+
61+
(async () => {
62+
const project = new ci.Project({
63+
appid: '<YOUR_APPID>',
64+
projectPath: path.join(__dirname, '../'),
65+
privateKeyPath: '<YOUR_PROJECT_KEY>',
66+
type: 'miniProgram',
67+
ignores: ['node_modules/**/*'],
68+
});
69+
70+
const uploadResult = await ci.upload({
71+
project,
72+
version: '<VERSION>',
73+
desc: '修复了一些已知问题',
74+
setting: {
75+
es6: true,
76+
es7: true,
77+
disableUseStrict: false,
78+
minify: true,
79+
codeProtect: true,
80+
autoPrefixWXSS: true,
81+
},
82+
onProgressUpdate: console.log,
83+
});
84+
85+
console.log(uploadResult);
86+
})();
87+
```
88+
89+
:::tip
90+
上传密钥可以在 “[微信公众平台](https://mp.weixin.qq.com/) - 开发 - 开发设置” 获取,并建议设置上传白名单 IP
91+
:::

0 commit comments

Comments
 (0)