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

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,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeMoreCompany = void 0;
3
+ exports.hasCompanyDutyKey = exports.normalizeMoreCompany = void 0;
4
4
  const index_1 = require("../../vendor/km-card-layout-core/index");
5
5
  const EMPTY_COMPANY_DUTY = {
6
6
  company: '',
@@ -88,6 +88,29 @@ const buildCards = (layouts) => {
88
88
  elements: decorateElements(layout.children || []),
89
89
  }));
90
90
  };
91
+ const hasCompanyDutyKey = (schemas) => {
92
+ const TARGET_KEYS = new Set([
93
+ 'company_duty_custom',
94
+ 'company_duty_1',
95
+ 'company_duty_2',
96
+ ]);
97
+ const traverse = (elements) => {
98
+ return elements.some(el => {
99
+ var _a;
100
+ // 命中 key
101
+ if (el.key && TARGET_KEYS.has(el.key)) {
102
+ return true;
103
+ }
104
+ // 递归 layout-panel
105
+ if (el.type === 'layout-panel' && ((_a = el.children) === null || _a === void 0 ? void 0 : _a.length)) {
106
+ return traverse(el.children);
107
+ }
108
+ return false;
109
+ });
110
+ };
111
+ return schemas.some(schema => traverse(schema.children));
112
+ };
113
+ exports.hasCompanyDutyKey = hasCompanyDutyKey;
91
114
  Component({
92
115
  options: {
93
116
  styleIsolation: 'apply-shared',
@@ -125,7 +148,7 @@ Component({
125
148
  methods: {
126
149
  rebuild() {
127
150
  const data = normalizeMoreCompany(this.data.data);
128
- const layoutInput = (0, index_1.processCardLayout)(this.data.layout, data);
151
+ const layoutInput = (0, exports.hasCompanyDutyKey)(this.data.layout) ? (0, index_1.processCardLayout)(this.data.layout, data) : this.data.layout;
129
152
  const rootData = handleSpecialFields(data);
130
153
  if (!layoutInput.length) {
131
154
  this.setData({ cards: [], rootData });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "km-card-layout-component-miniprogram",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "",
5
5
  "main": "miniprogram_dist/index.js",
6
6
  "miniprogram": "miniprogram_dist",
@@ -135,6 +135,36 @@ const buildCards = (layouts: CardLayoutSchema[]) => {
135
135
  }));
136
136
  };
137
137
 
138
+
139
+ export const hasCompanyDutyKey = (
140
+ schemas: CardLayoutSchema[]
141
+ ): boolean => {
142
+ const TARGET_KEYS = new Set([
143
+ 'company_duty_custom',
144
+ 'company_duty_1',
145
+ 'company_duty_2',
146
+ ]);
147
+
148
+ const traverse = (elements: CardElement[]): boolean => {
149
+ return elements.some(el => {
150
+ // 命中 key
151
+ if (el.key && TARGET_KEYS.has(el.key)) {
152
+ return true;
153
+ }
154
+
155
+ // 递归 layout-panel
156
+ if (el.type === 'layout-panel' && el.children?.length) {
157
+ return traverse(el.children);
158
+ }
159
+
160
+ return false;
161
+ });
162
+ };
163
+
164
+ return schemas.some(schema => traverse(schema.children));
165
+ };
166
+
167
+
138
168
  Component({
139
169
  options: {
140
170
  styleIsolation: 'apply-shared',
@@ -172,7 +202,7 @@ Component({
172
202
  methods: {
173
203
  rebuild() {
174
204
  const data = normalizeMoreCompany(this.data.data)
175
- const layoutInput = processCardLayout(this.data.layout, data as any);
205
+ const layoutInput = hasCompanyDutyKey(this.data.layout)?processCardLayout(this.data.layout, data as any): this.data.layout;
176
206
  const rootData = handleSpecialFields(data as any);
177
207
  if (!layoutInput.length) {
178
208
  this.setData({ cards: [], rootData });