cloud-web-corejs 1.1.0-dev.66 → 1.1.0-dev.68

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloud-web-corejs",
3
3
  "private": false,
4
- "version": "1.1.0-dev.66",
4
+ "version": "1.1.0-dev.68",
5
5
  "scripts": {
6
6
  "build:ace-resources": "node build/build-ace-resources.js",
7
7
  "build:tinymce-resources": "node build/build-tinymce-resources.js",
@@ -149,6 +149,7 @@
149
149
  "src/components/baseAlert",
150
150
  "src/components/baseAttachment",
151
151
  "src/components/baseArea",
152
+ "src/components/baseAutocomplete",
152
153
  "src/components/baseInputBatch",
153
154
  "src/components/baseInputExport",
154
155
  "src/components/baseInputNumber",
@@ -202,6 +202,10 @@ Vue.component("baseInputBatch", () =>
202
202
 
203
203
  Vue.component("baseArea", () => import("@base/components/baseArea/index.vue"));
204
204
 
205
+ Vue.component("baseAutocomplete", () =>
206
+ import("@base/components/baseAutocomplete/index.vue")
207
+ );
208
+
205
209
  Vue.component("baseInputExport", () =>
206
210
  import("@base/components/baseInputExport/index.vue")
207
211
  );
@@ -186,6 +186,10 @@ Vue.component("baseInputBatch", () =>
186
186
 
187
187
  Vue.component("baseArea", () => import("@base/components/baseArea/index.vue"));
188
188
 
189
+ Vue.component("baseAutocomplete", () =>
190
+ import("@base/components/baseAutocomplete/index.vue")
191
+ );
192
+
189
193
  Vue.component("baseInputExport", () =>
190
194
  import("@base/components/baseInputExport/index.vue")
191
195
  );
@@ -0,0 +1,393 @@
1
+ <template>
2
+ <el-autocomplete
3
+ ref="input"
4
+ v-model="displayValue"
5
+ class="base-autocomplete"
6
+ :disabled="disabled"
7
+ :readonly="readonly"
8
+ :size="size || undefined"
9
+ :placeholder="placeholder"
10
+ :clearable="clearable"
11
+ :fetch-suggestions="querySearchAsync"
12
+ :trigger-on-focus="triggerOnFocus"
13
+ :debounce="debounce"
14
+ :value-key="resolvedLabelField"
15
+ :prefix-icon="prefixIcon"
16
+ :suffix-icon="suffixIcon"
17
+ :popper-class="popperClassName"
18
+ @select="handleSelect"
19
+ @clear="handleClear"
20
+ @focus="handleFocus"
21
+ @blur="handleBlur"
22
+ @input="handleInputChange"
23
+ >
24
+ <template v-if="$slots.prefix" slot="prefix">
25
+ <slot name="prefix"></slot>
26
+ </template>
27
+ <template v-if="$slots.suffix" slot="suffix">
28
+ <slot name="suffix"></slot>
29
+ </template>
30
+ <template v-if="$slots.prepend" slot="prepend">
31
+ <slot name="prepend"></slot>
32
+ </template>
33
+ <template v-if="$slots.append" slot="append">
34
+ <slot name="append"></slot>
35
+ </template>
36
+ <template slot-scope="{ item }">
37
+ <slot :item="item">
38
+ <span v-if="itemTemplate" v-html="renderItemTemplate(item)"></span>
39
+ <span v-else v-html="renderHighlight(item)"></span>
40
+ </slot>
41
+ </template>
42
+ </el-autocomplete>
43
+ </template>
44
+
45
+ <script>
46
+ import {
47
+ hasValue,
48
+ trimText,
49
+ collectFill,
50
+ highlightKeyword,
51
+ } from "./query";
52
+
53
+ /**
54
+ * Vue 页面用的自动完成。输入框展示名称,v-model 存 ID。
55
+ * 取数方式和 el-tree 的 load 一样:页面自己请求,再 resolve 结果。
56
+ *
57
+ * <base-autocomplete
58
+ * v-model="form.saleOrgId"
59
+ * :label.sync="form.saleOrgName"
60
+ * :props="orgProps"
61
+ * :load="loadOrg"
62
+ * />
63
+ *
64
+ * orgProps: { value: "id", label: "name" }
65
+ * loadOrg(keyword, resolve) {
66
+ * this.$http({
67
+ * url: USER_PREFIX + "/sale_org/getAllList",
68
+ * method: "post",
69
+ * data: { keyword: keyword, enabled: true },
70
+ * success: (res) => resolve(res.objx || []),
71
+ * });
72
+ * }
73
+ */
74
+ export default {
75
+ name: "baseAutocomplete",
76
+ model: {
77
+ prop: "value",
78
+ event: "input",
79
+ },
80
+ props: {
81
+ value: {
82
+ default: null,
83
+ },
84
+ label: {
85
+ default: null,
86
+ },
87
+ /**
88
+ * 与 el-tree 的 props 相同角色:value 是 ID 字段,label 是展示字段。
89
+ */
90
+ props: {
91
+ type: Object,
92
+ default() {
93
+ return {
94
+ value: "id",
95
+ label: "name",
96
+ };
97
+ },
98
+ },
99
+ /**
100
+ * (keyword, resolve) => void。页面请求完成后 resolve(列表)。
101
+ */
102
+ load: {
103
+ type: Function,
104
+ default: null,
105
+ },
106
+ /**
107
+ * 只有 ID、没有名称时反查。(id, resolve) => void,resolve 一条记录或数组。
108
+ */
109
+ loadById: {
110
+ type: Function,
111
+ default: null,
112
+ },
113
+ fillConfig: {
114
+ type: Array,
115
+ default: () => [],
116
+ },
117
+ data: {
118
+ type: Object,
119
+ default: null,
120
+ },
121
+ itemTemplate: {
122
+ type: Function,
123
+ default: null,
124
+ },
125
+ placeholder: {
126
+ type: String,
127
+ default: "请输入关键词搜索",
128
+ },
129
+ disabled: {
130
+ type: Boolean,
131
+ default: false,
132
+ },
133
+ readonly: {
134
+ type: Boolean,
135
+ default: false,
136
+ },
137
+ clearable: {
138
+ type: Boolean,
139
+ default: true,
140
+ },
141
+ debounce: {
142
+ type: Number,
143
+ default: 300,
144
+ },
145
+ triggerOnFocus: {
146
+ type: Boolean,
147
+ default: false,
148
+ },
149
+ size: {
150
+ type: String,
151
+ default: "",
152
+ },
153
+ prefixIcon: {
154
+ type: String,
155
+ default: "",
156
+ },
157
+ suffixIcon: {
158
+ type: String,
159
+ default: "",
160
+ },
161
+ popperClass: {
162
+ type: String,
163
+ default: "",
164
+ },
165
+ },
166
+ data() {
167
+ return {
168
+ displayValue: null,
169
+ storedLabel: null,
170
+ isSelecting: false,
171
+ lastQueryKeyword: null,
172
+ querySeq: 0,
173
+ lookupSeq: 0,
174
+ };
175
+ },
176
+ computed: {
177
+ resolvedValueField() {
178
+ return trimText(this.props && this.props.value) || "id";
179
+ },
180
+ resolvedLabelField() {
181
+ return trimText(this.props && this.props.label) || "name";
182
+ },
183
+ popperClassName() {
184
+ return ["base-autocomplete-popper", this.popperClass]
185
+ .filter((item) => item)
186
+ .join(" ");
187
+ },
188
+ },
189
+ watch: {
190
+ label(val) {
191
+ this.storedLabel = val ?? null;
192
+ if (!this.isSelecting) {
193
+ this.displayValue = this.storedLabel;
194
+ }
195
+ if (!hasValue(val)) {
196
+ this.lookupLabel(this.value);
197
+ }
198
+ },
199
+ value(val) {
200
+ if (this.isSelecting) return;
201
+ this.lookupLabel(val);
202
+ },
203
+ },
204
+ created() {
205
+ this.storedLabel = this.label ?? null;
206
+ this.displayValue = this.storedLabel;
207
+ this.lookupLabel(this.value);
208
+ },
209
+ methods: {
210
+ focus() {
211
+ const input = this.$refs.input;
212
+ if (input && input.focus) input.focus();
213
+ },
214
+ resetQueryCache() {
215
+ this.lastQueryKeyword = null;
216
+ this._lastSuggestions = null;
217
+ },
218
+ querySearchAsync(queryString, cb) {
219
+ if (this.disabled || this.readonly) {
220
+ cb([]);
221
+ return;
222
+ }
223
+ const keyword = queryString == null ? "" : String(queryString);
224
+ if (!trimText(keyword)) {
225
+ this.resetQueryCache();
226
+ cb([]);
227
+ return;
228
+ }
229
+ if (
230
+ keyword === this.lastQueryKeyword
231
+ && this._lastSuggestions
232
+ && this._lastSuggestions.length
233
+ ) {
234
+ cb(this._lastSuggestions);
235
+ return;
236
+ }
237
+ this.lastQueryKeyword = keyword;
238
+ const seq = ++this.querySeq;
239
+ this.invokeLoad(keyword, seq, cb);
240
+ },
241
+ invokeLoad(keyword, seq, cb) {
242
+ if (typeof this.load !== "function") {
243
+ cb([]);
244
+ return;
245
+ }
246
+ let settled = false;
247
+ const done = (rows) => {
248
+ if (settled || seq !== this.querySeq) return;
249
+ settled = true;
250
+ const list = Array.isArray(rows) ? rows : [];
251
+ this._lastSuggestions = list;
252
+ cb(list);
253
+ };
254
+ try {
255
+ const ret = this.load(keyword, done);
256
+ if (ret && typeof ret.then === "function") {
257
+ ret
258
+ .then((rows) => {
259
+ if (Array.isArray(rows)) done(rows);
260
+ })
261
+ .catch(() => {
262
+ if (!settled) done([]);
263
+ });
264
+ }
265
+ } catch (e) {
266
+ done([]);
267
+ }
268
+ },
269
+ lookupLabel(id) {
270
+ if (!hasValue(id) || hasValue(this.storedLabel)) return;
271
+ if (typeof this.loadById !== "function") return;
272
+ const seq = ++this.lookupSeq;
273
+ let settled = false;
274
+ const done = (row) => {
275
+ if (settled || seq !== this.lookupSeq) return;
276
+ settled = true;
277
+ if (this.value !== id || hasValue(this.storedLabel)) return;
278
+ const record = Array.isArray(row) ? row[0] : row;
279
+ if (!record || typeof record !== "object") return;
280
+ const label = record[this.resolvedLabelField] ?? null;
281
+ this.storedLabel = label;
282
+ this.displayValue = label;
283
+ this.$emit("update:label", label);
284
+ };
285
+ try {
286
+ const ret = this.loadById(id, done);
287
+ if (ret && typeof ret.then === "function") {
288
+ ret
289
+ .then((row) => {
290
+ if (row && (Array.isArray(row) || typeof row === "object")) {
291
+ done(row);
292
+ }
293
+ })
294
+ .catch(() => {});
295
+ }
296
+ } catch (e) {
297
+ // 反查失败时保留空名称,页面仍可继续输入搜索
298
+ }
299
+ },
300
+ handleSelect(item) {
301
+ this.isSelecting = true;
302
+ try {
303
+ const row = item || {};
304
+ const id = row[this.resolvedValueField] ?? null;
305
+ const label = row[this.resolvedLabelField] ?? null;
306
+ const oldValue = this.value;
307
+ this.storedLabel = label;
308
+ this.displayValue = label;
309
+ this.$emit("input", id);
310
+ this.$emit("update:label", label);
311
+ const filled = collectFill(row, this.fillConfig);
312
+ if (this.data) {
313
+ Object.keys(filled).forEach((key) => {
314
+ this.$set(this.data, key, filled[key]);
315
+ });
316
+ }
317
+ this.$emit("fill", filled, row);
318
+ this.$emit("select", row);
319
+ this.$emit("change", id, oldValue, row);
320
+ } finally {
321
+ this.$nextTick(() => {
322
+ this.isSelecting = false;
323
+ });
324
+ }
325
+ },
326
+ handleClear() {
327
+ this.isSelecting = true;
328
+ const oldValue = this.value;
329
+ this.storedLabel = null;
330
+ this.displayValue = null;
331
+ this.resetQueryCache();
332
+ this.$emit("input", null);
333
+ this.$emit("update:label", null);
334
+ this.$emit("change", null, oldValue, null);
335
+ this.$emit("clear");
336
+ this.$nextTick(() => {
337
+ this.isSelecting = false;
338
+ });
339
+ },
340
+ handleInputChange(text) {
341
+ if (this.isSelecting) return;
342
+ this.$emit("input-change", text);
343
+ },
344
+ handleFocus(event) {
345
+ this.$emit("focus", event);
346
+ },
347
+ handleBlur(event) {
348
+ setTimeout(() => {
349
+ if (this.isSelecting) return;
350
+ if (this.displayValue !== this.storedLabel) {
351
+ this.displayValue = this.storedLabel;
352
+ }
353
+ }, 150);
354
+ this.$emit("blur", event);
355
+ },
356
+ renderHighlight(item) {
357
+ const row = item || {};
358
+ return highlightKeyword(
359
+ row[this.resolvedLabelField],
360
+ this.lastQueryKeyword
361
+ );
362
+ },
363
+ renderItemTemplate(item) {
364
+ if (typeof this.itemTemplate !== "function") return "";
365
+ try {
366
+ return this.itemTemplate(item) || "";
367
+ } catch (e) {
368
+ return this.renderHighlight(item);
369
+ }
370
+ },
371
+ },
372
+ };
373
+ </script>
374
+
375
+ <style lang="scss" scoped>
376
+ .base-autocomplete {
377
+ width: 100%;
378
+ }
379
+ </style>
380
+
381
+ <style lang="scss">
382
+ .base-autocomplete-popper {
383
+ .el-autocomplete-suggestion__list li {
384
+ font-size: 13px;
385
+ line-height: 1.6;
386
+ }
387
+ }
388
+
389
+ .base-autocomplete-highlight {
390
+ color: #409eff;
391
+ font-weight: bold;
392
+ }
393
+ </style>
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Vue 页面自动完成的展示与回填。取数由页面的 load 回调完成。
3
+ */
4
+
5
+ export function hasValue(val) {
6
+ return val !== null && val !== undefined && val !== "";
7
+ }
8
+
9
+ export function trimText(value) {
10
+ if (value == null) return "";
11
+ return String(value).trim();
12
+ }
13
+
14
+ /**
15
+ * 选中回填。兼容 target/source 与 targetFormField/sourceField。
16
+ */
17
+ export function collectFill(item, fillConfig) {
18
+ const filled = {};
19
+ const list = Array.isArray(fillConfig) ? fillConfig : [];
20
+ list.forEach((cfg) => {
21
+ if (!cfg) return;
22
+ const target = trimText(
23
+ cfg.target || cfg.targetFormField || cfg.targetField
24
+ );
25
+ const source = trimText(cfg.source || cfg.sourceField);
26
+ if (!target) return;
27
+ filled[target] = source ? (item ? item[source] ?? null : null) : null;
28
+ });
29
+ return filled;
30
+ }
31
+
32
+ export function escapeHtml(str) {
33
+ const map = {
34
+ "&": "&amp;",
35
+ "<": "&lt;",
36
+ ">": "&gt;",
37
+ '"': "&quot;",
38
+ "'": "&#39;",
39
+ };
40
+ return String(str == null ? "" : str).replace(/[&<>"']/g, (ch) => map[ch]);
41
+ }
42
+
43
+ export function highlightKeyword(text, keyword) {
44
+ const escaped = escapeHtml(text);
45
+ const raw = keyword == null ? "" : String(keyword);
46
+ if (!trimText(raw)) return escaped;
47
+ const kw = escapeHtml(raw).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
48
+ if (!kw) return escaped;
49
+ const re = new RegExp("(" + kw + ")", "gi");
50
+ return escaped.replace(
51
+ re,
52
+ '<span class="base-autocomplete-highlight">$1</span>'
53
+ );
54
+ }
@@ -157,4 +157,19 @@ export const constantRoutes = [
157
157
  },
158
158
  ],
159
159
  }] : []), */
160
+ {
161
+ path: "",
162
+ component: () => import("@/layout/index"),
163
+ children: [
164
+ {
165
+ path: "/demo/autocomplete",
166
+ component: () => import("@base/views/demo/autocomplete/index.vue"),
167
+ name: "demoAutocomplete",
168
+ meta: {
169
+ title: "用户自动完成示例",
170
+ icon: "user",
171
+ },
172
+ },
173
+ ],
174
+ },
160
175
  ];
@@ -42,6 +42,40 @@ function isBinaryRequestBody(data) {
42
42
  return typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(data);
43
43
  }
44
44
 
45
+ function isAbsoluteHttpUrl(url) {
46
+ return /^(https?:)?\/\//i.test(String(url || ""));
47
+ }
48
+
49
+ function toOrigin(url) {
50
+ try {
51
+ return new URL(String(url), window.location.href).origin;
52
+ } catch (e) {
53
+ return "";
54
+ }
55
+ }
56
+
57
+ // 相对地址走当前 baseURL,视为本系统后台。绝对地址只有和后台同源才加密。
58
+ function isOwnBackendRequest(config) {
59
+ const rawUrl = String((config && config.url) || "");
60
+ let targetOrigin = "";
61
+ if (isAbsoluteHttpUrl(rawUrl)) {
62
+ targetOrigin = toOrigin(rawUrl);
63
+ } else {
64
+ const baseUrl =
65
+ config && config.baseURL != null && config.baseURL !== ""
66
+ ? config.baseURL
67
+ : configUtil.baseUrl || "";
68
+ targetOrigin = isAbsoluteHttpUrl(baseUrl)
69
+ ? toOrigin(baseUrl)
70
+ : window.location.origin;
71
+ }
72
+ const ownBase = configUtil.baseUrl || "";
73
+ const ownOrigin = isAbsoluteHttpUrl(ownBase)
74
+ ? toOrigin(ownBase)
75
+ : window.location.origin;
76
+ return !!targetOrigin && targetOrigin === ownOrigin;
77
+ }
78
+
45
79
  // 调用方已经 stringify 成对象或数组文本时直接加密,避免再包一层字符串。
46
80
  function aesPlainText(data, useEmptyObject) {
47
81
  if (typeof data === "string") {
@@ -89,7 +123,11 @@ service.interceptors.request.use(
89
123
  );
90
124
  }
91
125
  const canEncryptBody = !isBinaryRequestBody(config.data);
92
- if (settingConfig.requestAesEnabled === true && canEncryptBody) {
126
+ if (
127
+ settingConfig.requestAesEnabled === true &&
128
+ canEncryptBody &&
129
+ isOwnBackendRequest(config)
130
+ ) {
93
131
  config.data = wrapAesBody(config.data, true);
94
132
  config.headers["Content-Type"] = "application/json;charset=UTF-8";
95
133
  } else if (