km-card-layout-component-miniprogram 0.1.14 → 0.1.15

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.
@@ -1,6 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeMoreCompany = void 0;
3
4
  const index_1 = require("../../vendor/km-card-layout-core/index");
5
+ const EMPTY_COMPANY_DUTY = {
6
+ company: '',
7
+ duty: '',
8
+ };
9
+ /**
10
+ * 规范化 moreCardInfo.company,保证长度始终为 2
11
+ */
12
+ function normalizeMoreCompany(data) {
13
+ var _a, _b;
14
+ const origin = (_b = (_a = data.user) === null || _a === void 0 ? void 0 : _a.moreCardInfo) === null || _b === void 0 ? void 0 : _b.company;
15
+ // 不存在 / 不是数组 → 不处理
16
+ if (!Array.isArray(origin)) {
17
+ return data;
18
+ }
19
+ // 长度 === 0 → 不处理
20
+ if (origin.length === 0) {
21
+ return data;
22
+ }
23
+ const normalized = origin.slice(0, 2);
24
+ while (normalized.length < 2) {
25
+ normalized.push({ ...EMPTY_COMPANY_DUTY });
26
+ }
27
+ return {
28
+ ...data,
29
+ user: {
30
+ ...data.user,
31
+ moreCardInfo: {
32
+ ...data.user.moreCardInfo,
33
+ company: normalized,
34
+ },
35
+ },
36
+ };
37
+ }
38
+ exports.normalizeMoreCompany = normalizeMoreCompany;
4
39
  const handleSpecialFields = (data) => {
5
40
  var _a;
6
41
  const user = (_a = data.user) !== null && _a !== void 0 ? _a : {};
@@ -89,8 +124,9 @@ Component({
89
124
  },
90
125
  methods: {
91
126
  rebuild() {
92
- const layoutInput = (0, index_1.processCardLayout)(this.data.layout, this.data.data);
93
- const rootData = handleSpecialFields(this.data.data);
127
+ const data = normalizeMoreCompany(this.data.data);
128
+ const layoutInput = (0, index_1.processCardLayout)(this.data.layout, data);
129
+ const rootData = handleSpecialFields(data);
94
130
  if (!layoutInput.length) {
95
131
  this.setData({ cards: [], rootData });
96
132
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "km-card-layout-component-miniprogram",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "",
5
5
  "main": "miniprogram_dist/index.js",
6
6
  "miniprogram": "miniprogram_dist",
@@ -19,6 +19,48 @@ type CompanyDuty = {
19
19
  duty: string;
20
20
  };
21
21
 
22
+
23
+
24
+ const EMPTY_COMPANY_DUTY: CompanyDuty = {
25
+ company: '',
26
+ duty: '',
27
+ };
28
+
29
+ /**
30
+ * 规范化 moreCardInfo.company,保证长度始终为 2
31
+ */
32
+ export function normalizeMoreCompany(data: AnyObject): AnyObject {
33
+ const origin = data.user?.moreCardInfo?.company;
34
+
35
+ // 不存在 / 不是数组 → 不处理
36
+ if (!Array.isArray(origin)) {
37
+ return data;
38
+ }
39
+
40
+ // 长度 === 0 → 不处理
41
+ if (origin.length === 0) {
42
+ return data;
43
+ }
44
+
45
+ const normalized = origin.slice(0, 2);
46
+
47
+ while (normalized.length < 2) {
48
+ normalized.push({ ...EMPTY_COMPANY_DUTY });
49
+ }
50
+
51
+ return {
52
+ ...data,
53
+ user: {
54
+ ...data.user,
55
+ moreCardInfo: {
56
+ ...data.user.moreCardInfo,
57
+ company: normalized,
58
+ },
59
+ },
60
+ };
61
+ }
62
+
63
+
22
64
  const handleSpecialFields = (data: { user: Record<string, any> }) => {
23
65
  const user = data.user ?? {};
24
66
  return {
@@ -129,8 +171,9 @@ Component({
129
171
  },
130
172
  methods: {
131
173
  rebuild() {
132
- const layoutInput = processCardLayout(this.data.layout, this.data.data);
133
- const rootData = handleSpecialFields(this.data.data);
174
+ const data = normalizeMoreCompany(this.data.data)
175
+ const layoutInput = processCardLayout(this.data.layout, data as any);
176
+ const rootData = handleSpecialFields(data as any);
134
177
  if (!layoutInput.length) {
135
178
  this.setData({ cards: [], rootData });
136
179
  return;