@adelie/wechat-miniprogram 0.0.0-stage → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/icon.svg +7 -0
- package/package.json +17 -3
- package/plugin.json +9 -0
- package/skills/wechat-miniprogram/SKILL.md +148 -0
- package/skills/wechat-miniprogram/scripts/add-ip2.mjs +358 -0
- package/skills/wechat-miniprogram/scripts/auto-submit.mjs +170 -0
- package/skills/wechat-miniprogram/scripts/check-session.mjs +40 -0
- package/skills/wechat-miniprogram/scripts/login2.mjs +226 -0
- package/skills/wechat-miniprogram/scripts/miniapp-info.mjs +67 -0
- package/skills/wechat-miniprogram/scripts/miniapp-nav.mjs +56 -0
- package/skills/wechat-miniprogram/scripts/package.json +12 -0
- package/skills/wechat-miniprogram/scripts/privacy-fill2.mjs +302 -0
- package/skills/wechat-miniprogram/scripts/probe-key-qr.mjs +147 -0
- package/skills/wechat-miniprogram/scripts/probe-privacy.mjs +73 -0
- package/skills/wechat-miniprogram/scripts/probe-privcheck.mjs +129 -0
- package/skills/wechat-miniprogram/scripts/probe-switch3.mjs +104 -0
- package/skills/wechat-miniprogram/scripts/reset-key2.mjs +259 -0
- package/skills/wechat-miniprogram/scripts/stealth.mjs +92 -0
- package/skills/wechat-miniprogram/scripts/submit-review4.mjs +186 -0
- package/skills/wechat-miniprogram/scripts/to-miniapp.mjs +136 -0
- package/skills/wechat-miniprogram/scripts/withdraw2.mjs +229 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/README.md +46 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/app.js +14 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/app.json +12 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/app.wxss +13 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/package.json +14 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.js +33 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.json +4 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.wxml +24 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/about/about.wxss +49 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.js +145 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.json +4 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.wxml +55 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/pages/index/index.wxss +173 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/preview.js +53 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/project.config.json +25 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/sitemap.json +9 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/tools/test-page.js +123 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/tools/validate.js +103 -0
- package/skills/wechat-miniprogram/templates/miniprogram-todo/upload.js +49 -0
- package/README.md +0 -3
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// 删除(撤回)审核版本:出管理员验证二维码 → 等扫码 → 完成删除 → 复核
|
|
2
|
+
// 用法: node withdraw2.mjs <qrPrefix> <statusPath> [超时分钟]
|
|
3
|
+
import { launchStealth } from "./stealth.mjs";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import crypto from "node:crypto";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { PNG } from "pngjs";
|
|
9
|
+
import jsQR from "jsqr";
|
|
10
|
+
|
|
11
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const qrPrefix = process.argv[2] || path.join(here, "del-qr.png");
|
|
13
|
+
const statusPath = process.argv[3] || path.join(here, "withdraw-status.json");
|
|
14
|
+
const timeoutMin = Number(process.argv[4] || 20);
|
|
15
|
+
const outDir = path.dirname(qrPrefix);
|
|
16
|
+
const base = path.basename(qrPrefix).replace(/\.png$/, "");
|
|
17
|
+
const write = (o) =>
|
|
18
|
+
fs.writeFileSync(statusPath, JSON.stringify({ at: new Date().toISOString(), ...o }, null, 2));
|
|
19
|
+
const log = (...a) => console.log(new Date().toISOString(), ...a);
|
|
20
|
+
|
|
21
|
+
function upscale3x(png) {
|
|
22
|
+
const s = 3,
|
|
23
|
+
b = new PNG({ width: png.width * s, height: png.height * s });
|
|
24
|
+
for (let y = 0; y < b.height; y++)
|
|
25
|
+
for (let x = 0; x < b.width; x++) {
|
|
26
|
+
const si = (((y / s) | 0) * png.width + ((x / s) | 0)) << 2,
|
|
27
|
+
di = (y * b.width + x) << 2;
|
|
28
|
+
b.data[di] = png.data[si];
|
|
29
|
+
b.data[di + 1] = png.data[si + 1];
|
|
30
|
+
b.data[di + 2] = png.data[si + 2];
|
|
31
|
+
b.data[di + 3] = 255;
|
|
32
|
+
}
|
|
33
|
+
return b;
|
|
34
|
+
}
|
|
35
|
+
function deliverQr(pngBuf) {
|
|
36
|
+
const png = PNG.sync.read(pngBuf);
|
|
37
|
+
const big = upscale3x(png);
|
|
38
|
+
const dec = jsQR(new Uint8Array(big.data), big.width, big.height);
|
|
39
|
+
const hash = crypto
|
|
40
|
+
.createHash("sha1")
|
|
41
|
+
.update(dec ? dec.data : PNG.sync.write(big))
|
|
42
|
+
.digest("hex")
|
|
43
|
+
.slice(0, 8);
|
|
44
|
+
const file = path.join(outDir, `${base}-${hash}.png`);
|
|
45
|
+
if (!fs.existsSync(file)) {
|
|
46
|
+
fs.writeFileSync(file, PNG.sync.write(big));
|
|
47
|
+
const re = new RegExp(`^${base}-[0-9a-f]{8}\\.png$`);
|
|
48
|
+
for (const f of fs.readdirSync(outDir))
|
|
49
|
+
if (re.test(f) && path.join(outDir, f) !== file) {
|
|
50
|
+
try {
|
|
51
|
+
fs.unlinkSync(path.join(outDir, f));
|
|
52
|
+
} catch {}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
file,
|
|
57
|
+
hash,
|
|
58
|
+
size: `${big.width}x${big.height}`,
|
|
59
|
+
decoded: dec ? dec.data.slice(0, 100) : null,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const ctx = await launchStealth(path.join(here, "profile"), { headless: false });
|
|
64
|
+
const page = ctx.pages()[0] || (await ctx.newPage());
|
|
65
|
+
await page.goto("https://mp.weixin.qq.com/", { waitUntil: "domcontentloaded", timeout: 60000 });
|
|
66
|
+
await page.waitForTimeout(10000);
|
|
67
|
+
const token = (page.url().match(/token=(\d+)/) || [])[1];
|
|
68
|
+
if (!token) {
|
|
69
|
+
write({ state: "NOT_LOGGED_IN" });
|
|
70
|
+
log("NOT LOGGED IN");
|
|
71
|
+
await ctx.close().catch(() => {});
|
|
72
|
+
process.exit(2);
|
|
73
|
+
}
|
|
74
|
+
await page
|
|
75
|
+
.goto(`https://mp.weixin.qq.com/wxamp/wacodepage/getcodepage?token=${token}&lang=zh_CN`, {
|
|
76
|
+
waitUntil: "commit",
|
|
77
|
+
timeout: 60000,
|
|
78
|
+
})
|
|
79
|
+
.catch(() => {});
|
|
80
|
+
await page.waitForTimeout(12000);
|
|
81
|
+
|
|
82
|
+
const dlgText = () =>
|
|
83
|
+
page.evaluate(() => {
|
|
84
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
85
|
+
(e) => e.offsetWidth > 200 && e.offsetHeight > 120,
|
|
86
|
+
);
|
|
87
|
+
return ds
|
|
88
|
+
.map((e) => (e.innerText || "").replace(/\s+/g, " ").trim())
|
|
89
|
+
.filter(Boolean)
|
|
90
|
+
.join(" || ")
|
|
91
|
+
.slice(0, 400);
|
|
92
|
+
});
|
|
93
|
+
const pageText = () => page.evaluate(() => (document.body.innerText || "").replace(/\s+/g, " "));
|
|
94
|
+
|
|
95
|
+
const p = await page.evaluate(() => {
|
|
96
|
+
const btn = Array.from(document.querySelectorAll("button,a")).filter(
|
|
97
|
+
(e) => e.offsetWidth && (e.innerText || "").trim() === "删除",
|
|
98
|
+
)[0];
|
|
99
|
+
if (!btn) return null;
|
|
100
|
+
btn.scrollIntoView({ block: "center" });
|
|
101
|
+
const r = btn.getBoundingClientRect();
|
|
102
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
103
|
+
});
|
|
104
|
+
if (!p) {
|
|
105
|
+
write({ state: "NO_DELETE_BTN" });
|
|
106
|
+
log("NO_DELETE_BTN");
|
|
107
|
+
await ctx.close().catch(() => {});
|
|
108
|
+
process.exit(3);
|
|
109
|
+
}
|
|
110
|
+
await page.mouse.click(p.x, p.y);
|
|
111
|
+
await page.waitForTimeout(4000);
|
|
112
|
+
|
|
113
|
+
const grabQr = async () => {
|
|
114
|
+
const el = await page.evaluateHandle(() => {
|
|
115
|
+
const ds = Array.from(document.querySelectorAll('[class*="dialog"],[class*="modal"]')).filter(
|
|
116
|
+
(e) => e.offsetWidth > 200 && e.offsetHeight > 120,
|
|
117
|
+
);
|
|
118
|
+
for (const d of ds)
|
|
119
|
+
for (const img of d.querySelectorAll("img")) {
|
|
120
|
+
const r = img.getBoundingClientRect();
|
|
121
|
+
if (r.width > 120) return img;
|
|
122
|
+
}
|
|
123
|
+
for (const d of ds)
|
|
124
|
+
for (const cv of d.querySelectorAll("canvas")) {
|
|
125
|
+
const r = cv.getBoundingClientRect();
|
|
126
|
+
if (r.width > 120) return cv;
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
});
|
|
130
|
+
const node = el.asElement();
|
|
131
|
+
if (!node) return null;
|
|
132
|
+
const buf = await node.screenshot().catch(() => null);
|
|
133
|
+
return buf ? deliverQr(buf) : null;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
let t = await dlgText();
|
|
137
|
+
log("dialog:", t);
|
|
138
|
+
write({ state: "DIALOG", dialog: t });
|
|
139
|
+
let qrInfo = null,
|
|
140
|
+
lastQrAt = 0,
|
|
141
|
+
done = false;
|
|
142
|
+
const deadline = Date.now() + timeoutMin * 60 * 1000;
|
|
143
|
+
|
|
144
|
+
while (Date.now() < deadline) {
|
|
145
|
+
t = await dlgText();
|
|
146
|
+
if (!/请使用微信扫描二维码进行验证|请在手机上进行确认/.test(t)) {
|
|
147
|
+
done = true;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
if (/失效|过期|刷新|重新获取/.test(t)) {
|
|
151
|
+
const r = await page
|
|
152
|
+
.evaluate(() => {
|
|
153
|
+
const ds = Array.from(
|
|
154
|
+
document.querySelectorAll('[class*="dialog"],[class*="modal"]'),
|
|
155
|
+
).filter((e) => e.offsetWidth > 200);
|
|
156
|
+
for (const d of ds)
|
|
157
|
+
for (const e of d.querySelectorAll("a,button,span,div")) {
|
|
158
|
+
if (e.children.length === 0 && /刷新|重新获取/.test((e.innerText || "").trim())) {
|
|
159
|
+
const r = e.getBoundingClientRect();
|
|
160
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
})
|
|
165
|
+
.catch(() => null);
|
|
166
|
+
if (r) {
|
|
167
|
+
await page.mouse.click(r.x, r.y);
|
|
168
|
+
await page.waitForTimeout(3000);
|
|
169
|
+
}
|
|
170
|
+
qrInfo = null;
|
|
171
|
+
lastQrAt = 0;
|
|
172
|
+
}
|
|
173
|
+
if (!qrInfo || Date.now() - lastQrAt > 15000) {
|
|
174
|
+
const info = await grabQr();
|
|
175
|
+
if (info) {
|
|
176
|
+
const changed = !qrInfo || info.decoded !== qrInfo.decoded;
|
|
177
|
+
qrInfo = info;
|
|
178
|
+
lastQrAt = Date.now();
|
|
179
|
+
if (changed) {
|
|
180
|
+
log(
|
|
181
|
+
"QR_READY",
|
|
182
|
+
path.basename(info.file),
|
|
183
|
+
info.size,
|
|
184
|
+
info.decoded ? "decoded-ok" : "UNREADABLE",
|
|
185
|
+
);
|
|
186
|
+
write({ state: "WAIT_SCAN", ...info, dialog: t });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
await page.waitForTimeout(2000);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!done) {
|
|
194
|
+
write({ state: "TIMEOUT" });
|
|
195
|
+
log("TIMEOUT");
|
|
196
|
+
await ctx.close().catch(() => {});
|
|
197
|
+
process.exit(4);
|
|
198
|
+
}
|
|
199
|
+
log("verified, dialog now:", t);
|
|
200
|
+
await page.waitForTimeout(4000);
|
|
201
|
+
|
|
202
|
+
const c = await page.evaluate(() => {
|
|
203
|
+
const e = Array.from(document.querySelectorAll("button,a,span,div"))
|
|
204
|
+
.filter(
|
|
205
|
+
(x) =>
|
|
206
|
+
x.offsetWidth &&
|
|
207
|
+
x.children.length === 0 &&
|
|
208
|
+
/^(确定|确认|删除)$/.test((x.innerText || "").trim()),
|
|
209
|
+
)
|
|
210
|
+
.pop();
|
|
211
|
+
if (!e) return null;
|
|
212
|
+
const r = e.getBoundingClientRect();
|
|
213
|
+
return { x: r.x + r.width / 2, y: r.y + r.height / 2, t: (e.innerText || "").trim() };
|
|
214
|
+
});
|
|
215
|
+
log("confirm:", JSON.stringify(c));
|
|
216
|
+
if (c) {
|
|
217
|
+
await page.mouse.click(c.x, c.y);
|
|
218
|
+
await page.waitForTimeout(7000);
|
|
219
|
+
}
|
|
220
|
+
await page.screenshot({ path: path.join(outDir, `${base}-done.png`) }).catch(() => {});
|
|
221
|
+
const after = await pageText();
|
|
222
|
+
log("after:", after.slice(0, 700));
|
|
223
|
+
write({
|
|
224
|
+
state: "DONE",
|
|
225
|
+
hasReviewVersion: /审核版本\s*版本号/.test(after),
|
|
226
|
+
after: after.slice(0, 600),
|
|
227
|
+
});
|
|
228
|
+
await ctx.close().catch(() => {});
|
|
229
|
+
process.exit(0);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# 待办清单小程序(todo-miniprogram)
|
|
2
|
+
|
|
3
|
+
一个纯离线、零后端、零第三方依赖的微信小程序:记待办、勾选完成、删除、按「全部 / 未完成 / 已完成」筛选,数据存在本机 `wx.setStorageSync`。
|
|
4
|
+
|
|
5
|
+
- AppID:先在 `project.config.json` 里填自己的 AppID(本模板留作占位符 `wxTEMPLATE_PLACEHOLDER`)
|
|
6
|
+
|
|
7
|
+
## 目录
|
|
8
|
+
|
|
9
|
+
| 路径 | 作用 |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| `app.json` / `app.js` / `app.wxss` | 全局配置、启动逻辑、全局样式 |
|
|
12
|
+
| `pages/index/` | 首页:新增、勾选、删除、筛选、清空已完成 |
|
|
13
|
+
| `pages/about/` | 关于页 |
|
|
14
|
+
| `project.config.json` | 项目配置(AppID、编译设置、打包忽略) |
|
|
15
|
+
| `sitemap.json` | 搜索索引配置 |
|
|
16
|
+
| `upload.js` | 用 miniprogram-ci 上传代码,生成开发版 |
|
|
17
|
+
| `preview.js` | 用 miniprogram-ci 生成体验版二维码 |
|
|
18
|
+
| `tools/validate.js` | 本地静态校验(结构 / JSON / JS 语法 / WXML 插值) |
|
|
19
|
+
| `tools/test-page.js` | 无头逻辑测试(打桩 `wx` / `Page`,跑页面的增删改查) |
|
|
20
|
+
|
|
21
|
+
## 本地校验
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install
|
|
25
|
+
npm run validate # 结构与语法校验
|
|
26
|
+
node tools/test-page.js # 页面逻辑单测
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 上传(Linux 命令行,无需微信开发者工具)
|
|
30
|
+
|
|
31
|
+
1. 在 mp.weixin.qq.com → 管理 → 开发管理 → 开发设置 → 小程序代码上传,生成上传密钥,下载 `private.<appid>.key`。
|
|
32
|
+
2. 运行:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
MP_APPID=wx你的AppID MP_KEY_PATH=/path/to/private.<appid>.key MP_VERSION=1.0.0 node upload.js
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
上传成功后,到小程序后台「管理 → 版本管理」把该开发版设为体验版或提交审核。
|
|
39
|
+
|
|
40
|
+
体验版二维码:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
MP_APPID=wx你的AppID MP_KEY_PATH=/path/to/private.<appid>.key node preview.js
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> 密钥文件只放服务器或本机,不要提交进仓库、不要贴到聊天里。
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pages": ["pages/index/index", "pages/about/about"],
|
|
3
|
+
"window": {
|
|
4
|
+
"backgroundTextStyle": "light",
|
|
5
|
+
"navigationBarBackgroundColor": "#ffffff",
|
|
6
|
+
"navigationBarTitleText": "待办清单",
|
|
7
|
+
"navigationBarTextStyle": "black",
|
|
8
|
+
"backgroundColor": "#f6f7f8"
|
|
9
|
+
},
|
|
10
|
+
"style": "v2",
|
|
11
|
+
"sitemapLocation": "sitemap.json"
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
page {
|
|
2
|
+
background: #f6f7f8;
|
|
3
|
+
color: #1a1b1c;
|
|
4
|
+
font-size: 30rpx;
|
|
5
|
+
line-height: 1.5;
|
|
6
|
+
font-family: -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.page {
|
|
10
|
+
min-height: 100vh;
|
|
11
|
+
padding: 24rpx 24rpx 48rpx;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "todo-miniprogram",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "简单待办清单小程序(微信)",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"validate": "node tools/validate.js",
|
|
8
|
+
"upload": "node upload.js",
|
|
9
|
+
"preview": "node preview.js"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"miniprogram-ci": "^2.1.31"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const app = getApp();
|
|
2
|
+
|
|
3
|
+
Page({
|
|
4
|
+
data: {
|
|
5
|
+
version: "1.0.0",
|
|
6
|
+
lastLaunch: "",
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
onLoad() {
|
|
10
|
+
let last = "";
|
|
11
|
+
try {
|
|
12
|
+
const ts = wx.getStorageSync("app:lastLaunch");
|
|
13
|
+
if (ts) {
|
|
14
|
+
const d = new Date(ts);
|
|
15
|
+
const pad = (n) => (n < 10 ? `0${n}` : `${n}`);
|
|
16
|
+
last = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
17
|
+
}
|
|
18
|
+
} catch (e) {
|
|
19
|
+
last = "";
|
|
20
|
+
}
|
|
21
|
+
this.setData({
|
|
22
|
+
version: (app && app.globalData && app.globalData.version) || "1.0.0",
|
|
23
|
+
lastLaunch: last,
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
copyLink() {
|
|
28
|
+
wx.setClipboardData({
|
|
29
|
+
data: "https://github.com/",
|
|
30
|
+
success: () => wx.showToast({ title: "已复制", icon: "none" }),
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<view class="page">
|
|
2
|
+
<view class="card">
|
|
3
|
+
<view class="card__title">待办清单</view>
|
|
4
|
+
<view class="card__desc">一个离线可用的极简待办小程序,数据只存在你的手机里(wx.setStorage),不联网、不上传。</view>
|
|
5
|
+
</view>
|
|
6
|
+
|
|
7
|
+
<view class="card">
|
|
8
|
+
<view class="row">
|
|
9
|
+
<text class="row__k">版本</text>
|
|
10
|
+
<text class="row__v">{{version}}</text>
|
|
11
|
+
</view>
|
|
12
|
+
<view class="row">
|
|
13
|
+
<text class="row__k">上次启动</text>
|
|
14
|
+
<text class="row__v">{{lastLaunch || '—'}}</text>
|
|
15
|
+
</view>
|
|
16
|
+
</view>
|
|
17
|
+
|
|
18
|
+
<view class="tips">
|
|
19
|
+
<view class="tips__title">怎么用</view>
|
|
20
|
+
<view class="tips__item">· 顶部输入框写内容,回车或点「添加」</view>
|
|
21
|
+
<view class="tips__item">· 点条目或左侧圆圈切换完成状态</view>
|
|
22
|
+
<view class="tips__item">· 右侧「删除」删单条,「清空已完成」批量清理</view>
|
|
23
|
+
</view>
|
|
24
|
+
</view>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
.card {
|
|
2
|
+
background: #ffffff;
|
|
3
|
+
border-radius: 20rpx;
|
|
4
|
+
padding: 32rpx 28rpx;
|
|
5
|
+
margin-bottom: 24rpx;
|
|
6
|
+
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.card__title {
|
|
10
|
+
font-size: 36rpx;
|
|
11
|
+
font-weight: 600;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.card__desc {
|
|
15
|
+
margin-top: 14rpx;
|
|
16
|
+
font-size: 27rpx;
|
|
17
|
+
color: #7e8081;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.row {
|
|
21
|
+
display: flex;
|
|
22
|
+
justify-content: space-between;
|
|
23
|
+
padding: 14rpx 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.row__k {
|
|
27
|
+
color: #7e8081;
|
|
28
|
+
font-size: 28rpx;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.row__v {
|
|
32
|
+
font-size: 28rpx;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.tips {
|
|
36
|
+
padding: 0 8rpx;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.tips__title {
|
|
40
|
+
font-size: 28rpx;
|
|
41
|
+
font-weight: 600;
|
|
42
|
+
margin-bottom: 12rpx;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.tips__item {
|
|
46
|
+
font-size: 27rpx;
|
|
47
|
+
color: #7e8081;
|
|
48
|
+
line-height: 1.9;
|
|
49
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const STORAGE_KEY = "todos:v1";
|
|
2
|
+
|
|
3
|
+
// 同一毫秒内可能连续添加多条,单用时间戳会撞 id,这里加随机后缀保证唯一
|
|
4
|
+
function makeId() {
|
|
5
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function formatTime(ts) {
|
|
9
|
+
const d = new Date(ts);
|
|
10
|
+
const pad = (n) => (n < 10 ? `0${n}` : `${n}`);
|
|
11
|
+
const now = new Date();
|
|
12
|
+
const sameDay = d.toDateString() === now.toDateString();
|
|
13
|
+
if (sameDay) return `今天 ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
14
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Page({
|
|
18
|
+
data: {
|
|
19
|
+
todos: [],
|
|
20
|
+
visible: [],
|
|
21
|
+
input: "",
|
|
22
|
+
filter: "all", // all | active | done
|
|
23
|
+
counts: { total: 0, active: 0, done: 0 },
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
onLoad() {
|
|
27
|
+
this.load();
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
// ---------- 数据 ----------
|
|
31
|
+
load() {
|
|
32
|
+
let todos = [];
|
|
33
|
+
try {
|
|
34
|
+
todos = wx.getStorageSync(STORAGE_KEY) || [];
|
|
35
|
+
} catch (e) {
|
|
36
|
+
todos = [];
|
|
37
|
+
}
|
|
38
|
+
if (!Array.isArray(todos)) todos = [];
|
|
39
|
+
todos = todos.map((t) => ({ ...t, timeText: formatTime(t.createdAt || Date.now()) }));
|
|
40
|
+
this.commit(todos);
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
persist(todos) {
|
|
44
|
+
try {
|
|
45
|
+
wx.setStorageSync(
|
|
46
|
+
STORAGE_KEY,
|
|
47
|
+
todos.map(({ timeText, ...rest }) => rest),
|
|
48
|
+
);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
wx.showToast({ title: "保存失败", icon: "none" });
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
// 统一出口:落盘 + 计数 + 按筛选条件生成可见列表
|
|
55
|
+
commit(todos) {
|
|
56
|
+
const done = todos.filter((t) => t.done).length;
|
|
57
|
+
const total = todos.length;
|
|
58
|
+
const { filter } = this.data;
|
|
59
|
+
const visible = todos.filter((t) => {
|
|
60
|
+
if (filter === "active") return !t.done;
|
|
61
|
+
if (filter === "done") return t.done;
|
|
62
|
+
return true;
|
|
63
|
+
});
|
|
64
|
+
this.setData({
|
|
65
|
+
todos,
|
|
66
|
+
visible,
|
|
67
|
+
counts: { total, done, active: total - done },
|
|
68
|
+
});
|
|
69
|
+
this.persist(todos);
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// ---------- 交互 ----------
|
|
73
|
+
onInput(e) {
|
|
74
|
+
this.setData({ input: e.detail.value });
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
addTodo() {
|
|
78
|
+
const text = (this.data.input || "").trim();
|
|
79
|
+
if (!text) {
|
|
80
|
+
wx.showToast({ title: "先写点内容", icon: "none" });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
const todos = [
|
|
85
|
+
{ id: makeId(), text, done: false, createdAt: now, timeText: formatTime(now) },
|
|
86
|
+
...this.data.todos,
|
|
87
|
+
];
|
|
88
|
+
this.setData({ input: "" });
|
|
89
|
+
this.commit(todos);
|
|
90
|
+
wx.vibrateShort({ type: "light" });
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
toggleTodo(e) {
|
|
94
|
+
const id = e.currentTarget.dataset.id;
|
|
95
|
+
const todos = this.data.todos.map((t) => (t.id === id ? { ...t, done: !t.done } : t));
|
|
96
|
+
if (this.data.filter !== "all") {
|
|
97
|
+
// 在筛选视图里切换状态时,让列表立刻反映当前筛选
|
|
98
|
+
this.commit(todos);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.commit(todos);
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
removeTodo(e) {
|
|
105
|
+
const id = e.currentTarget.dataset.id;
|
|
106
|
+
const target = this.data.todos.find((t) => t.id === id);
|
|
107
|
+
wx.showModal({
|
|
108
|
+
title: "删除这条待办?",
|
|
109
|
+
content: target ? target.text.slice(0, 40) : "",
|
|
110
|
+
confirmText: "删除",
|
|
111
|
+
confirmColor: "#fa5151",
|
|
112
|
+
success: (res) => {
|
|
113
|
+
if (!res.confirm) return;
|
|
114
|
+
this.commit(this.data.todos.filter((t) => t.id !== id));
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
clearDone() {
|
|
120
|
+
const done = this.data.counts.done;
|
|
121
|
+
if (!done) {
|
|
122
|
+
wx.showToast({ title: "没有已完成的", icon: "none" });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
wx.showModal({
|
|
126
|
+
title: `清空 ${done} 条已完成?`,
|
|
127
|
+
content: "清空后无法恢复",
|
|
128
|
+
confirmText: "清空",
|
|
129
|
+
confirmColor: "#fa5151",
|
|
130
|
+
success: (res) => {
|
|
131
|
+
if (!res.confirm) return;
|
|
132
|
+
this.commit(this.data.todos.filter((t) => !t.done));
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
setFilter(e) {
|
|
138
|
+
const filter = e.currentTarget.dataset.filter;
|
|
139
|
+
this.setData({ filter }, () => this.commit(this.data.todos));
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
goAbout() {
|
|
143
|
+
wx.navigateTo({ url: "/pages/about/about" });
|
|
144
|
+
},
|
|
145
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<view class="page">
|
|
2
|
+
<view class="header">
|
|
3
|
+
<view class="header__title">待办清单</view>
|
|
4
|
+
<view class="header__stat">
|
|
5
|
+
<text class="stat__num">{{counts.active}}</text>
|
|
6
|
+
<text class="stat__label">进行中</text>
|
|
7
|
+
<text class="stat__sep">·</text>
|
|
8
|
+
<text class="stat__num">{{counts.done}}</text>
|
|
9
|
+
<text class="stat__label">已完成</text>
|
|
10
|
+
</view>
|
|
11
|
+
</view>
|
|
12
|
+
|
|
13
|
+
<view class="composer">
|
|
14
|
+
<input
|
|
15
|
+
class="composer__input"
|
|
16
|
+
value="{{input}}"
|
|
17
|
+
placeholder="添加一条待办…"
|
|
18
|
+
placeholder-class="composer__placeholder"
|
|
19
|
+
confirm-type="done"
|
|
20
|
+
maxlength="80"
|
|
21
|
+
bindinput="onInput"
|
|
22
|
+
bindconfirm="addTodo"
|
|
23
|
+
/>
|
|
24
|
+
<button class="composer__btn" size="mini" bindtap="addTodo">添加</button>
|
|
25
|
+
</view>
|
|
26
|
+
|
|
27
|
+
<view class="tabs">
|
|
28
|
+
<view class="tab {{filter === 'all' ? 'tab_active' : ''}}" data-filter="all" bindtap="setFilter">全部</view>
|
|
29
|
+
<view class="tab {{filter === 'active' ? 'tab_active' : ''}}" data-filter="active" bindtap="setFilter">进行中</view>
|
|
30
|
+
<view class="tab {{filter === 'done' ? 'tab_active' : ''}}" data-filter="done" bindtap="setFilter">已完成</view>
|
|
31
|
+
</view>
|
|
32
|
+
|
|
33
|
+
<view class="list">
|
|
34
|
+
<view class="item {{item.done ? 'item_done' : ''}}" wx:for="{{visible}}" wx:key="id">
|
|
35
|
+
<view class="item__check" data-id="{{item.id}}" bindtap="toggleTodo">
|
|
36
|
+
<view class="item__box">{{item.done ? '✓' : ''}}</view>
|
|
37
|
+
</view>
|
|
38
|
+
<view class="item__body" data-id="{{item.id}}" bindtap="toggleTodo">
|
|
39
|
+
<text class="item__text">{{item.text}}</text>
|
|
40
|
+
<text class="item__time">{{item.timeText}}</text>
|
|
41
|
+
</view>
|
|
42
|
+
<view class="item__del" data-id="{{item.id}}" catchtap="removeTodo">删除</view>
|
|
43
|
+
</view>
|
|
44
|
+
|
|
45
|
+
<view class="empty" wx:if="{{visible.length === 0}}">
|
|
46
|
+
<view class="empty__title">{{counts.total === 0 ? '还没有待办' : '这个筛选下是空的'}}</view>
|
|
47
|
+
<view class="empty__desc">在上面的输入框里写一条,回车或点「添加」</view>
|
|
48
|
+
</view>
|
|
49
|
+
</view>
|
|
50
|
+
|
|
51
|
+
<view class="footer">
|
|
52
|
+
<view class="footer__btn" bindtap="clearDone">清空已完成</view>
|
|
53
|
+
<view class="footer__btn" bindtap="goAbout">关于</view>
|
|
54
|
+
</view>
|
|
55
|
+
</view>
|