km-card-layout-component-miniprogram 0.1.35 → 0.1.36
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.
|
@@ -37,7 +37,6 @@ function normalizeMoreCompany(data) {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
exports.normalizeMoreCompany = normalizeMoreCompany;
|
|
40
|
-
const delay = (ms = 200) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
41
40
|
const pickCardId = (layout, idx) => {
|
|
42
41
|
if (layout && (layout.name || layout.id))
|
|
43
42
|
return layout.name || layout.id;
|
|
@@ -52,6 +51,9 @@ const buildCards = (layouts) => {
|
|
|
52
51
|
elements: layout.children || [],
|
|
53
52
|
}));
|
|
54
53
|
};
|
|
54
|
+
const nextTick = () => new Promise((resolve) => {
|
|
55
|
+
wx.nextTick(() => resolve());
|
|
56
|
+
});
|
|
55
57
|
Component({
|
|
56
58
|
options: {
|
|
57
59
|
styleIsolation: "apply-shared",
|
|
@@ -106,8 +108,8 @@ Component({
|
|
|
106
108
|
},
|
|
107
109
|
async handleDrawCanvas(options) {
|
|
108
110
|
try {
|
|
109
|
-
if ((options === null || options === void 0 ? void 0 : options.
|
|
110
|
-
await
|
|
111
|
+
if ((options === null || options === void 0 ? void 0 : options.waitForReady) !== false) {
|
|
112
|
+
await nextTick();
|
|
111
113
|
}
|
|
112
114
|
const canvas = this.selectComponent(`#layout-canvas`);
|
|
113
115
|
await canvas.draw(this);
|
|
@@ -120,9 +122,9 @@ Component({
|
|
|
120
122
|
},
|
|
121
123
|
async handleDrawShareCanvas() {
|
|
122
124
|
var _a, _b, _c;
|
|
123
|
-
//
|
|
124
|
-
await
|
|
125
|
-
const layoutPath = await this.handleDrawCanvas({
|
|
125
|
+
// 等 setData / 组件渲染完成
|
|
126
|
+
await nextTick();
|
|
127
|
+
const layoutPath = await this.handleDrawCanvas({ waitForReady: false });
|
|
126
128
|
if (!layoutPath)
|
|
127
129
|
return;
|
|
128
130
|
const shareCanvas = this.selectComponent(`#share-canvas`);
|
package/package.json
CHANGED
|
@@ -63,8 +63,6 @@ type RenderCard = {
|
|
|
63
63
|
elements: RenderElement[];
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
const delay = (ms = 200) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
67
|
-
|
|
68
66
|
const pickCardId = (layout: any, idx: number) => {
|
|
69
67
|
if (layout && (layout.name || layout.id)) return layout.name || layout.id;
|
|
70
68
|
return `card-${idx}`;
|
|
@@ -80,6 +78,11 @@ const buildCards = (layouts: CardLayoutSchema[]) => {
|
|
|
80
78
|
}));
|
|
81
79
|
};
|
|
82
80
|
|
|
81
|
+
const nextTick = () =>
|
|
82
|
+
new Promise<void>((resolve) => {
|
|
83
|
+
wx.nextTick(() => resolve());
|
|
84
|
+
});
|
|
85
|
+
|
|
83
86
|
Component({
|
|
84
87
|
options: {
|
|
85
88
|
styleIsolation: "apply-shared",
|
|
@@ -133,11 +136,12 @@ Component({
|
|
|
133
136
|
this.setData({ cards, rootData, firstCard: [cards[0]] });
|
|
134
137
|
},
|
|
135
138
|
|
|
136
|
-
async handleDrawCanvas(options?: {
|
|
139
|
+
async handleDrawCanvas(options?: { waitForReady?: boolean }) {
|
|
137
140
|
try {
|
|
138
|
-
if (options?.
|
|
139
|
-
await
|
|
141
|
+
if (options?.waitForReady !== false) {
|
|
142
|
+
await nextTick();
|
|
140
143
|
}
|
|
144
|
+
|
|
141
145
|
const canvas = this.selectComponent(`#layout-canvas`);
|
|
142
146
|
await canvas.draw(this);
|
|
143
147
|
const filePath = await canvas.toTempFilePath();
|
|
@@ -148,10 +152,10 @@ Component({
|
|
|
148
152
|
},
|
|
149
153
|
|
|
150
154
|
async handleDrawShareCanvas() {
|
|
151
|
-
//
|
|
152
|
-
await
|
|
155
|
+
// 等 setData / 组件渲染完成
|
|
156
|
+
await nextTick();
|
|
153
157
|
|
|
154
|
-
const layoutPath = await this.handleDrawCanvas({
|
|
158
|
+
const layoutPath = await this.handleDrawCanvas({ waitForReady: false });
|
|
155
159
|
if (!layoutPath) return;
|
|
156
160
|
|
|
157
161
|
const shareCanvas = this.selectComponent(`#share-canvas`) as any;
|