cloud-web-corejs 1.0.325 → 1.0.327
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 +2 -1
- package/src/app-bootstrap.js +4 -0
- package/src/app-bootstrap.sync.js +4 -0
- package/src/components/baseAutocomplete/README.md +157 -0
- package/src/components/baseAutocomplete/index.vue +489 -0
- package/src/components/baseAutocomplete/query.js +36 -0
- package/src/components/xform/form-designer/form-widget/field-widget/autocomplete-widget.vue +1 -1
- package/src/components/xform/form-designer/form-widget/field-widget/cascader-widget.vue +403 -10
- package/src/components/xform/form-designer/form-widget/field-widget/fieldMixin.js +6 -0
- package/src/components/xform/form-designer/form-widget/field-widget/vabUpload2-widget.vue +325 -59
- package/src/components/xform/form-designer/setting-panel/indexMixin.js +52 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/event-handler/onClear-editor.vue +30 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/event-handler/onLazyLoad-editor.vue +34 -0
- package/src/components/xform/form-designer/setting-panel/property-editor/field-cascader/cascader-lazy-editor.vue +108 -0
- package/src/components/xform/form-designer/setting-panel/propertyRegister.js +3 -0
- package/src/components/xform/form-designer/widget-panel/widgetsConfig.js +7 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloud-web-corejs",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.327",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vue-cli-service serve",
|
|
7
7
|
"check:package-resources": "node build/check-package-resources.js",
|
|
@@ -127,6 +127,7 @@
|
|
|
127
127
|
"src/components/baseAlert",
|
|
128
128
|
"src/components/baseAttachment",
|
|
129
129
|
"src/components/baseArea",
|
|
130
|
+
"src/components/baseAutocomplete",
|
|
130
131
|
"src/components/baseInputBatch",
|
|
131
132
|
"src/components/baseInputExport",
|
|
132
133
|
"src/components/baseInputNumber",
|
package/src/app-bootstrap.js
CHANGED
|
@@ -199,6 +199,10 @@ Vue.component("baseInputBatch", () =>
|
|
|
199
199
|
|
|
200
200
|
Vue.component("baseArea", () => import("@base/components/baseArea/index.vue"));
|
|
201
201
|
|
|
202
|
+
Vue.component("baseAutocomplete", () =>
|
|
203
|
+
import("@base/components/baseAutocomplete/index.vue")
|
|
204
|
+
);
|
|
205
|
+
|
|
202
206
|
Vue.component("baseInputExport", () =>
|
|
203
207
|
import("@base/components/baseInputExport/index.vue")
|
|
204
208
|
);
|
|
@@ -183,6 +183,10 @@ Vue.component("baseInputBatch", () =>
|
|
|
183
183
|
|
|
184
184
|
Vue.component("baseArea", () => import("@base/components/baseArea/index.vue"));
|
|
185
185
|
|
|
186
|
+
Vue.component("baseAutocomplete", () =>
|
|
187
|
+
import("@base/components/baseAutocomplete/index.vue")
|
|
188
|
+
);
|
|
189
|
+
|
|
186
190
|
Vue.component("baseInputExport", () =>
|
|
187
191
|
import("@base/components/baseInputExport/index.vue")
|
|
188
192
|
);
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# base-autocomplete 自动完成
|
|
2
|
+
|
|
3
|
+
Vue 页面用的远程搜索输入框。输入框展示名称,`v-model` 存 ID。取数方式和 `el-tree` 的 `load` 一样:页面自己请求,再把结果交给组件。
|
|
4
|
+
|
|
5
|
+
- 组件位置:`src/components/baseAutocomplete/`
|
|
6
|
+
- 全局注册名:`base-autocomplete`(`src/app-bootstrap.js`、`src/app-bootstrap.sync.js`)
|
|
7
|
+
- 示例页面:`src/views/demo/autocomplete/index.vue`(路由 `/#/demo/autocomplete`)
|
|
8
|
+
|
|
9
|
+
和 xform 里的「自动完成」字段不是同一个组件。本组件给普通 Vue 页面用,不读取表单设计器的 `script-code`。
|
|
10
|
+
|
|
11
|
+
## 快速上手
|
|
12
|
+
|
|
13
|
+
按姓名查用户。下拉只显示姓名,输入的关键词会高亮。
|
|
14
|
+
|
|
15
|
+
```vue
|
|
16
|
+
<base-autocomplete
|
|
17
|
+
v-model="form.userId"
|
|
18
|
+
:label.sync="form.nickName"
|
|
19
|
+
:props="userProps"
|
|
20
|
+
:load="loadUser"
|
|
21
|
+
placeholder="输入姓名搜索"
|
|
22
|
+
/>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
data() {
|
|
27
|
+
return {
|
|
28
|
+
userProps: { value: "id", label: "nickName" },
|
|
29
|
+
form: { userId: null, nickName: null },
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
methods: {
|
|
33
|
+
loadUser(keyword, resolve) {
|
|
34
|
+
this.$http({
|
|
35
|
+
url: USER_PREFIX + "/user/listCurrentPage",
|
|
36
|
+
method: "post",
|
|
37
|
+
isLoading: false,
|
|
38
|
+
data: {
|
|
39
|
+
current: 1,
|
|
40
|
+
size: 20,
|
|
41
|
+
searchCount: false,
|
|
42
|
+
enabled: true,
|
|
43
|
+
nickName: keyword,
|
|
44
|
+
},
|
|
45
|
+
success: (res) => {
|
|
46
|
+
const rows = (res.objx && res.objx.records) || res.objx || [];
|
|
47
|
+
resolve(Array.isArray(rows) ? rows : []);
|
|
48
|
+
},
|
|
49
|
+
fail: () => resolve([]),
|
|
50
|
+
error: () => resolve([]),
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
选中后 `form.userId` 是用户 ID,`form.nickName` 是姓名。输入了但没选中就离开输入框时,文字会还原成已保存的姓名,下拉和高亮会关掉。
|
|
57
|
+
|
|
58
|
+
## 属性
|
|
59
|
+
|
|
60
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
61
|
+
|---|---|---|---|
|
|
62
|
+
| `value` / `v-model` | any | `null` | 选中项的 ID |
|
|
63
|
+
| `label` | any | `null` | 输入框展示文字。用 `.sync` 写回 |
|
|
64
|
+
| `props` | Object | `{ value: "id", label: "name" }` | `value` 是候选项里的 ID 字段,`label` 是展示字段 |
|
|
65
|
+
| `load` | Function | `null` | `(keyword, resolve) => void`。请求完成后 `resolve(列表)`。也可以返回 `Promise<数组>` |
|
|
66
|
+
| `loadById` | Function | `null` | `(id, resolve) => void`。只有 ID、没有名称时反查。`resolve` 一条记录或数组的第一项 |
|
|
67
|
+
| `placeholder` | String | `请输入关键词搜索` | 占位文字 |
|
|
68
|
+
| `disabled` | Boolean | `false` | 禁用:变灰、不能聚焦、不查询、不出现清空按钮 |
|
|
69
|
+
| `readonly` | Boolean | `false` | 只读:可以聚焦和选中文字,不能输入、不查询、不出现清空按钮 |
|
|
70
|
+
| `clearable` | Boolean | `true` | 有内容时悬停显示清空按钮 |
|
|
71
|
+
| `debounce` | Number | `300` | 输入防抖毫秒数 |
|
|
72
|
+
| `triggerOnFocus` | Boolean | `false` | 聚焦且输入框为空时是否查询。默认空内容不查询 |
|
|
73
|
+
| `size` | String | `""` | 传给 `el-autocomplete`。留空则跟随 Element 当前尺寸 |
|
|
74
|
+
| `prefixIcon` | String | `""` | 前置图标类名 |
|
|
75
|
+
| `suffixIcon` | String | `el-icon-tickets` | 后置图标类名。有内容并悬停出清空按钮时,这个图标会隐藏。传 `""` 可去掉 |
|
|
76
|
+
| `popperClass` | String | `""` | 追加到下拉浮层上的类名 |
|
|
77
|
+
| `dropdownMaxWidth` | Number / String | `480` | 下拉最大宽度。最小宽度是输入框宽度,文字超出后换行 |
|
|
78
|
+
| `itemTemplate` | Function | `null` | `(item) => html`。自定义下拉项 HTML。写了默认插槽时不使用 |
|
|
79
|
+
|
|
80
|
+
`props.label` 是候选项上的字段名,`label` 是当前显示出来的文字,两者不是同一个值。
|
|
81
|
+
|
|
82
|
+
## 事件
|
|
83
|
+
|
|
84
|
+
| 事件 | 时机 | 参数 |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| `input` | 选中或清空 | ID。配合 `v-model` |
|
|
87
|
+
| `update:label` | 选中、清空,或按 ID 反查出名称 | 展示文字。配合 `label.sync` |
|
|
88
|
+
| `select` | 选中一项 | 选中的那一行。其他字段在这里回填 |
|
|
89
|
+
| `change` | 选中或清空 | `(id, oldId, row)`。清空时 `id`、`row` 为 `null` |
|
|
90
|
+
| `clear` | 点击清空 | 无 |
|
|
91
|
+
| `input-change` | 输入框文字变化,且不是选中引起的 | 当前输入文本 |
|
|
92
|
+
| `focus` / `blur` | 聚焦、失焦 | 原生事件 |
|
|
93
|
+
|
|
94
|
+
只处理选中用 `select`。其他字段也在 `select` 里写。选中和清空都要处理用 `change`,只处理清空用 `clear`。
|
|
95
|
+
|
|
96
|
+
```vue
|
|
97
|
+
<base-autocomplete
|
|
98
|
+
v-model="form.userId"
|
|
99
|
+
:label.sync="form.nickName"
|
|
100
|
+
:props="{ value: 'id', label: 'nickName' }"
|
|
101
|
+
:load="loadUser"
|
|
102
|
+
@select="handleSelect"
|
|
103
|
+
@clear="handleClear"
|
|
104
|
+
/>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
handleSelect(row) {
|
|
109
|
+
this.form.loginAccount = row.loginAccount;
|
|
110
|
+
},
|
|
111
|
+
handleClear() {
|
|
112
|
+
this.form.loginAccount = null;
|
|
113
|
+
},
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## 按 ID 回显名称
|
|
117
|
+
|
|
118
|
+
编辑页只有 ID、名称还没带上时,传 `load-by-id`。名称已经有值时不会再请求。
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
loadUserById(id, resolve) {
|
|
122
|
+
this.$http({
|
|
123
|
+
url: USER_PREFIX + "/user/get",
|
|
124
|
+
method: "post",
|
|
125
|
+
isLoading: false,
|
|
126
|
+
data: { id: id },
|
|
127
|
+
success: (res) => resolve(res.objx || null),
|
|
128
|
+
fail: () => resolve(null),
|
|
129
|
+
error: () => resolve(null),
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## 下拉展示
|
|
135
|
+
|
|
136
|
+
默认用 `props.label` 对应的字段做下拉文字,并把当前输入的关键词标成蓝色加粗。匹配不区分大小写。
|
|
137
|
+
|
|
138
|
+
自己写默认插槽后,组件不再套这层高亮:
|
|
139
|
+
|
|
140
|
+
```vue
|
|
141
|
+
<base-autocomplete :load="loadUser" :props="userProps" v-model="form.userId" :label.sync="form.nickName">
|
|
142
|
+
<template slot-scope="{ item }">
|
|
143
|
+
<span>{{ item.nickName }}</span>
|
|
144
|
+
<span>{{ item.loginAccount }}</span>
|
|
145
|
+
</template>
|
|
146
|
+
</base-autocomplete>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
还可以用 `prefix`、`suffix`、`prepend`、`append` 插槽,对应 `el-input` 的同名插槽。
|
|
150
|
+
|
|
151
|
+
## 行为说明
|
|
152
|
+
|
|
153
|
+
- 关键词为空(含只有空格)时不调用 `load`。
|
|
154
|
+
- 相同关键词且上次有结果时,不再重复请求。
|
|
155
|
+
- 未选中新项就失焦:输入框还原为已保存的 `label`,下拉关闭,关键词高亮清除。已保存的 ID 不变。
|
|
156
|
+
- 点清空:ID 和名称一起变成 `null`,下拉关闭。焦点还在时可以继续输入并重新查询。
|
|
157
|
+
- `disabled`、`readonly` 时不发起查询。
|
|
@@ -0,0 +1,489 @@
|
|
|
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="$t1(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
|
+
highlightKeyword,
|
|
50
|
+
} from "./query";
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Vue 页面用的自动完成。输入框展示名称,v-model 存 ID。
|
|
54
|
+
* 取数方式和 el-tree 的 load 一样:页面自己请求,再 resolve 结果。
|
|
55
|
+
*
|
|
56
|
+
* <base-autocomplete
|
|
57
|
+
* v-model="form.saleOrgId"
|
|
58
|
+
* :label.sync="form.saleOrgName"
|
|
59
|
+
* :props="orgProps"
|
|
60
|
+
* :load="loadOrg"
|
|
61
|
+
* />
|
|
62
|
+
*
|
|
63
|
+
* orgProps: { value: "id", label: "name" }
|
|
64
|
+
* loadOrg(keyword, resolve) {
|
|
65
|
+
* this.$http({
|
|
66
|
+
* url: USER_PREFIX + "/sale_org/getAllList",
|
|
67
|
+
* method: "post",
|
|
68
|
+
* data: { keyword: keyword, enabled: true },
|
|
69
|
+
* success: (res) => resolve(res.objx || []),
|
|
70
|
+
* });
|
|
71
|
+
* }
|
|
72
|
+
*/
|
|
73
|
+
export default {
|
|
74
|
+
name: "baseAutocomplete",
|
|
75
|
+
model: {
|
|
76
|
+
prop: "value",
|
|
77
|
+
event: "input",
|
|
78
|
+
},
|
|
79
|
+
props: {
|
|
80
|
+
value: {
|
|
81
|
+
default: null,
|
|
82
|
+
},
|
|
83
|
+
label: {
|
|
84
|
+
default: null,
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* 与 el-tree 的 props 相同角色:value 是 ID 字段,label 是展示字段。
|
|
88
|
+
*/
|
|
89
|
+
props: {
|
|
90
|
+
type: Object,
|
|
91
|
+
default() {
|
|
92
|
+
return {
|
|
93
|
+
value: "id",
|
|
94
|
+
label: "name",
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* (keyword, resolve) => void。页面请求完成后 resolve(列表)。
|
|
100
|
+
*/
|
|
101
|
+
load: {
|
|
102
|
+
type: Function,
|
|
103
|
+
default: null,
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* 只有 ID、没有名称时反查。(id, resolve) => void,resolve 一条记录或数组。
|
|
107
|
+
*/
|
|
108
|
+
loadById: {
|
|
109
|
+
type: Function,
|
|
110
|
+
default: null,
|
|
111
|
+
},
|
|
112
|
+
itemTemplate: {
|
|
113
|
+
type: Function,
|
|
114
|
+
default: null,
|
|
115
|
+
},
|
|
116
|
+
placeholder: {
|
|
117
|
+
type: String,
|
|
118
|
+
default: "请输入关键词搜索",
|
|
119
|
+
},
|
|
120
|
+
disabled: {
|
|
121
|
+
type: Boolean,
|
|
122
|
+
default: false,
|
|
123
|
+
},
|
|
124
|
+
readonly: {
|
|
125
|
+
type: Boolean,
|
|
126
|
+
default: false,
|
|
127
|
+
},
|
|
128
|
+
clearable: {
|
|
129
|
+
type: Boolean,
|
|
130
|
+
default: true,
|
|
131
|
+
},
|
|
132
|
+
debounce: {
|
|
133
|
+
type: Number,
|
|
134
|
+
default: 300,
|
|
135
|
+
},
|
|
136
|
+
triggerOnFocus: {
|
|
137
|
+
type: Boolean,
|
|
138
|
+
default: false,
|
|
139
|
+
},
|
|
140
|
+
size: {
|
|
141
|
+
type: String,
|
|
142
|
+
default: "",
|
|
143
|
+
},
|
|
144
|
+
prefixIcon: {
|
|
145
|
+
type: String,
|
|
146
|
+
default: "",
|
|
147
|
+
},
|
|
148
|
+
suffixIcon: {
|
|
149
|
+
type: String,
|
|
150
|
+
default: "el-icon-tickets",
|
|
151
|
+
},
|
|
152
|
+
popperClass: {
|
|
153
|
+
type: String,
|
|
154
|
+
default: "",
|
|
155
|
+
},
|
|
156
|
+
/**
|
|
157
|
+
* 下拉最大宽度。最小宽度始终是输入框宽度,超出后换行。
|
|
158
|
+
*/
|
|
159
|
+
dropdownMaxWidth: {
|
|
160
|
+
type: [Number, String],
|
|
161
|
+
default: 480,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
data() {
|
|
165
|
+
return {
|
|
166
|
+
displayValue: null,
|
|
167
|
+
storedLabel: null,
|
|
168
|
+
isSelecting: false,
|
|
169
|
+
focused: false,
|
|
170
|
+
lastQueryKeyword: null,
|
|
171
|
+
querySeq: 0,
|
|
172
|
+
lookupSeq: 0,
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
computed: {
|
|
176
|
+
resolvedValueField() {
|
|
177
|
+
return trimText(this.props && this.props.value) || "id";
|
|
178
|
+
},
|
|
179
|
+
resolvedLabelField() {
|
|
180
|
+
return trimText(this.props && this.props.label) || "name";
|
|
181
|
+
},
|
|
182
|
+
popperClassName() {
|
|
183
|
+
return ["base-autocomplete-popper", this.popperClass]
|
|
184
|
+
.filter((item) => item)
|
|
185
|
+
.join(" ");
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
watch: {
|
|
189
|
+
label(val) {
|
|
190
|
+
this.storedLabel = val ?? null;
|
|
191
|
+
if (!this.isSelecting) {
|
|
192
|
+
this.displayValue = this.storedLabel;
|
|
193
|
+
}
|
|
194
|
+
if (!hasValue(val)) {
|
|
195
|
+
this.lookupLabel(this.value);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
value(val) {
|
|
199
|
+
if (this.isSelecting) return;
|
|
200
|
+
this.lookupLabel(val);
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
created() {
|
|
204
|
+
this.storedLabel = this.label ?? null;
|
|
205
|
+
this.displayValue = this.storedLabel;
|
|
206
|
+
this.lookupLabel(this.value);
|
|
207
|
+
},
|
|
208
|
+
mounted() {
|
|
209
|
+
this.syncDropdownWidth();
|
|
210
|
+
},
|
|
211
|
+
methods: {
|
|
212
|
+
focus() {
|
|
213
|
+
const input = this.$refs.input;
|
|
214
|
+
if (input && input.focus) input.focus();
|
|
215
|
+
},
|
|
216
|
+
resetQueryCache() {
|
|
217
|
+
this.lastQueryKeyword = null;
|
|
218
|
+
this._lastSuggestions = null;
|
|
219
|
+
},
|
|
220
|
+
querySearchAsync(queryString, cb) {
|
|
221
|
+
if (this.disabled || this.readonly) {
|
|
222
|
+
cb([]);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const keyword = queryString == null ? "" : String(queryString);
|
|
226
|
+
if (!trimText(keyword)) {
|
|
227
|
+
this.resetQueryCache();
|
|
228
|
+
cb([]);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (
|
|
232
|
+
keyword === this.lastQueryKeyword
|
|
233
|
+
&& this._lastSuggestions
|
|
234
|
+
&& this._lastSuggestions.length
|
|
235
|
+
) {
|
|
236
|
+
cb(this._lastSuggestions);
|
|
237
|
+
this.syncDropdownWidth();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
this.lastQueryKeyword = keyword;
|
|
241
|
+
const seq = ++this.querySeq;
|
|
242
|
+
this.invokeLoad(keyword, seq, cb);
|
|
243
|
+
},
|
|
244
|
+
invokeLoad(keyword, seq, cb) {
|
|
245
|
+
if (typeof this.load !== "function") {
|
|
246
|
+
cb([]);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
let settled = false;
|
|
250
|
+
const done = (rows) => {
|
|
251
|
+
if (settled || seq !== this.querySeq) return;
|
|
252
|
+
settled = true;
|
|
253
|
+
if (!this.focused) {
|
|
254
|
+
this.lastQueryKeyword = null;
|
|
255
|
+
this._lastSuggestions = null;
|
|
256
|
+
cb([]);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const list = Array.isArray(rows) ? rows : [];
|
|
260
|
+
this._lastSuggestions = list;
|
|
261
|
+
cb(list);
|
|
262
|
+
this.syncDropdownWidth();
|
|
263
|
+
};
|
|
264
|
+
try {
|
|
265
|
+
const ret = this.load(keyword, done);
|
|
266
|
+
if (ret && typeof ret.then === "function") {
|
|
267
|
+
ret
|
|
268
|
+
.then((rows) => {
|
|
269
|
+
if (Array.isArray(rows)) done(rows);
|
|
270
|
+
})
|
|
271
|
+
.catch(() => {
|
|
272
|
+
if (!settled) done([]);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
} catch (e) {
|
|
276
|
+
done([]);
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
lookupLabel(id) {
|
|
280
|
+
if (!hasValue(id) || hasValue(this.storedLabel)) return;
|
|
281
|
+
if (typeof this.loadById !== "function") return;
|
|
282
|
+
const seq = ++this.lookupSeq;
|
|
283
|
+
let settled = false;
|
|
284
|
+
const done = (row) => {
|
|
285
|
+
if (settled || seq !== this.lookupSeq) return;
|
|
286
|
+
settled = true;
|
|
287
|
+
if (this.value !== id || hasValue(this.storedLabel)) return;
|
|
288
|
+
const record = Array.isArray(row) ? row[0] : row;
|
|
289
|
+
if (!record || typeof record !== "object") return;
|
|
290
|
+
const label = record[this.resolvedLabelField] ?? null;
|
|
291
|
+
this.storedLabel = label;
|
|
292
|
+
this.displayValue = label;
|
|
293
|
+
this.$emit("update:label", label);
|
|
294
|
+
};
|
|
295
|
+
try {
|
|
296
|
+
const ret = this.loadById(id, done);
|
|
297
|
+
if (ret && typeof ret.then === "function") {
|
|
298
|
+
ret
|
|
299
|
+
.then((row) => {
|
|
300
|
+
if (row && (Array.isArray(row) || typeof row === "object")) {
|
|
301
|
+
done(row);
|
|
302
|
+
}
|
|
303
|
+
})
|
|
304
|
+
.catch(() => {});
|
|
305
|
+
}
|
|
306
|
+
} catch (e) {
|
|
307
|
+
// 反查失败时保留空名称,页面仍可继续输入搜索
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
handleSelect(item) {
|
|
311
|
+
this.isSelecting = true;
|
|
312
|
+
try {
|
|
313
|
+
const row = item || {};
|
|
314
|
+
const id = row[this.resolvedValueField] ?? null;
|
|
315
|
+
const label = row[this.resolvedLabelField] ?? null;
|
|
316
|
+
const oldValue = this.value;
|
|
317
|
+
this.storedLabel = label;
|
|
318
|
+
this.displayValue = label;
|
|
319
|
+
this.$emit("input", id);
|
|
320
|
+
this.$emit("update:label", label);
|
|
321
|
+
this.$emit("select", row);
|
|
322
|
+
this.$emit("change", id, oldValue, row);
|
|
323
|
+
} finally {
|
|
324
|
+
this.$nextTick(() => {
|
|
325
|
+
this.isSelecting = false;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
handleClear() {
|
|
330
|
+
this.isSelecting = true;
|
|
331
|
+
const oldValue = this.value;
|
|
332
|
+
this.storedLabel = null;
|
|
333
|
+
this.displayValue = null;
|
|
334
|
+
this.resetQueryCache();
|
|
335
|
+
this.$emit("input", null);
|
|
336
|
+
this.$emit("update:label", null);
|
|
337
|
+
this.$emit("change", null, oldValue, null);
|
|
338
|
+
this.$emit("clear");
|
|
339
|
+
// 清空按钮会把 el-autocomplete 的 activated 关掉,且不会再次触发 focus。
|
|
340
|
+
// 焦点还在时要重新打开,否则继续输入不会再出下拉。
|
|
341
|
+
this.keepSearching();
|
|
342
|
+
this.$nextTick(() => {
|
|
343
|
+
this.isSelecting = false;
|
|
344
|
+
this.keepSearching();
|
|
345
|
+
});
|
|
346
|
+
},
|
|
347
|
+
keepSearching() {
|
|
348
|
+
const input = this.$refs.input;
|
|
349
|
+
if (!input || !this.focused) return;
|
|
350
|
+
input.activated = true;
|
|
351
|
+
input.suggestionDisabled = false;
|
|
352
|
+
},
|
|
353
|
+
handleInputChange(text) {
|
|
354
|
+
if (this.isSelecting) return;
|
|
355
|
+
this.$emit("input-change", text);
|
|
356
|
+
},
|
|
357
|
+
handleFocus(event) {
|
|
358
|
+
this.focused = true;
|
|
359
|
+
const input = this.$refs.input;
|
|
360
|
+
if (input) input.suggestionDisabled = false;
|
|
361
|
+
this.syncDropdownWidth();
|
|
362
|
+
this.$emit("focus", event);
|
|
363
|
+
},
|
|
364
|
+
syncDropdownWidth() {
|
|
365
|
+
this.$nextTick(() => {
|
|
366
|
+
const ac = this.$refs.input;
|
|
367
|
+
if (!ac || !ac.$el) return;
|
|
368
|
+
const popper = ac.$refs.suggestions && ac.$refs.suggestions.$el;
|
|
369
|
+
if (!popper) return;
|
|
370
|
+
const inputWidth = ac.$el.offsetWidth;
|
|
371
|
+
if (inputWidth) {
|
|
372
|
+
popper.style.setProperty(
|
|
373
|
+
"--base-autocomplete-min-width",
|
|
374
|
+
inputWidth + "px"
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
const maxWidth = this.dropdownMaxWidth;
|
|
378
|
+
let maxText = "";
|
|
379
|
+
if (typeof maxWidth === "number") {
|
|
380
|
+
maxText = maxWidth + "px";
|
|
381
|
+
} else if (maxWidth) {
|
|
382
|
+
maxText = String(maxWidth);
|
|
383
|
+
}
|
|
384
|
+
if (maxText) {
|
|
385
|
+
popper.style.setProperty("--base-autocomplete-max-width", maxText);
|
|
386
|
+
}
|
|
387
|
+
if (ac.$refs.suggestions.updatePopper) {
|
|
388
|
+
ac.$refs.suggestions.updatePopper();
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
},
|
|
392
|
+
handleBlur(event) {
|
|
393
|
+
this.focused = false;
|
|
394
|
+
this.$emit("blur", event);
|
|
395
|
+
setTimeout(() => {
|
|
396
|
+
if (this.isSelecting) return;
|
|
397
|
+
this.lastQueryKeyword = null;
|
|
398
|
+
this._lastSuggestions = null;
|
|
399
|
+
this.closeSuggestions();
|
|
400
|
+
if (this.displayValue !== this.storedLabel) {
|
|
401
|
+
this.displayValue = this.storedLabel;
|
|
402
|
+
}
|
|
403
|
+
}, 150);
|
|
404
|
+
},
|
|
405
|
+
closeSuggestions() {
|
|
406
|
+
const input = this.$refs.input;
|
|
407
|
+
if (!input) return;
|
|
408
|
+
input.activated = false;
|
|
409
|
+
input.suggestionDisabled = true;
|
|
410
|
+
input.highlightedIndex = -1;
|
|
411
|
+
if (Array.isArray(input.suggestions)) input.suggestions = [];
|
|
412
|
+
},
|
|
413
|
+
renderHighlight(item) {
|
|
414
|
+
const row = item || {};
|
|
415
|
+
return highlightKeyword(
|
|
416
|
+
row[this.resolvedLabelField],
|
|
417
|
+
this.lastQueryKeyword
|
|
418
|
+
);
|
|
419
|
+
},
|
|
420
|
+
renderItemTemplate(item) {
|
|
421
|
+
if (typeof this.itemTemplate !== "function") return "";
|
|
422
|
+
try {
|
|
423
|
+
return this.itemTemplate(item) || "";
|
|
424
|
+
} catch (e) {
|
|
425
|
+
return this.renderHighlight(item);
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
};
|
|
430
|
+
</script>
|
|
431
|
+
|
|
432
|
+
<style lang="scss" scoped>
|
|
433
|
+
.base-autocomplete {
|
|
434
|
+
width: 100%;
|
|
435
|
+
}
|
|
436
|
+
</style>
|
|
437
|
+
|
|
438
|
+
<style lang="scss">
|
|
439
|
+
.base-autocomplete.el-autocomplete .el-input .el-input__suffix {
|
|
440
|
+
top: 0;
|
|
441
|
+
height: 100%;
|
|
442
|
+
display: flex;
|
|
443
|
+
align-items: center;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.base-autocomplete.el-autocomplete .el-input .el-input__suffix-inner {
|
|
447
|
+
display: inline-flex;
|
|
448
|
+
align-items: center;
|
|
449
|
+
height: 100%;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
.base-autocomplete.el-autocomplete .el-input .el-input__icon {
|
|
453
|
+
float: none !important;
|
|
454
|
+
line-height: 1 !important;
|
|
455
|
+
display: inline-flex;
|
|
456
|
+
align-items: center;
|
|
457
|
+
justify-content: center;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
.base-autocomplete.el-autocomplete .el-input__suffix-inner:has(.el-input__clear) > .el-input__icon:not(.el-input__clear) {
|
|
461
|
+
display: none;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
.base-autocomplete-popper.el-autocomplete-suggestion {
|
|
465
|
+
width: auto !important;
|
|
466
|
+
min-width: var(--base-autocomplete-min-width) !important;
|
|
467
|
+
max-width: var(--base-autocomplete-max-width, 480px) !important;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
.base-autocomplete-popper {
|
|
471
|
+
.el-autocomplete-suggestion__list li {
|
|
472
|
+
height: auto;
|
|
473
|
+
padding-top: 6px;
|
|
474
|
+
padding-bottom: 6px;
|
|
475
|
+
font-size: 13px;
|
|
476
|
+
line-height: 1.6;
|
|
477
|
+
white-space: normal;
|
|
478
|
+
word-break: break-word;
|
|
479
|
+
overflow-wrap: anywhere;
|
|
480
|
+
overflow: visible;
|
|
481
|
+
text-overflow: unset;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.base-autocomplete-highlight {
|
|
486
|
+
color: #409eff;
|
|
487
|
+
font-weight: bold;
|
|
488
|
+
}
|
|
489
|
+
</style>
|