@56os/ui-components 0.0.0-stage → 0.2.0
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/README.md +100 -2
- package/package.json +39 -4
- package/src/components/CurrencyInput.vue +190 -0
- package/src/components/CustomerSelect.vue +319 -0
- package/src/index.ts +9 -0
- package/src/setup.ts +42 -0
- package/src/shims-vue.d.ts +5 -0
package/README.md
CHANGED
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @56os/ui-components
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
56os 通用 Vue 表单控件包:`CustomerSelect`、`CurrencyInput`。
|
|
4
|
+
|
|
5
|
+
> 包内**不**绑定业务仓 `@/api` / `$filter`。
|
|
6
|
+
> 检索编排仍用 `@56os/search-fields`;本包只提供可复用控件。
|
|
7
|
+
|
|
8
|
+
## 仓库
|
|
9
|
+
|
|
10
|
+
GitLab:http://203.170.59.233:7001/npm/56os-ui-components
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# 发布到 npm/npmmirror 后
|
|
16
|
+
pnpm add @56os/ui-components@^0.2.0
|
|
17
|
+
# 或 cnpm i @56os/ui-components@^0.2.0
|
|
18
|
+
|
|
19
|
+
# 本地联调(未发版时)
|
|
20
|
+
# 与包同级:customer-management / 56os-base-operations
|
|
21
|
+
pnpm add @56os/ui-components@file:../56os-ui-components
|
|
22
|
+
# 在 经营业务|财务管理|产品管理|经营分析 子目录内:
|
|
23
|
+
pnpm add @56os/ui-components@file:../../56os-ui-components
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 接入(CustomerSelect 需注入 API)
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { setupUiComponents, CustomerSelect, CurrencyInput } from '@56os/ui-components';
|
|
30
|
+
import {
|
|
31
|
+
customerNameSelectPage,
|
|
32
|
+
entSupplierNameSelectPage,
|
|
33
|
+
fleetNameSelectPage,
|
|
34
|
+
supplierNameSelectPage
|
|
35
|
+
} from '@/api/bus/warehouseOrder';
|
|
36
|
+
|
|
37
|
+
setupUiComponents({
|
|
38
|
+
customerSelectApis: {
|
|
39
|
+
customerNameSelectPage,
|
|
40
|
+
entSupplierNameSelectPage,
|
|
41
|
+
fleetNameSelectPage,
|
|
42
|
+
supplierNameSelectPage
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// 可选:交给 search-fields 默认渲染 customerSelect
|
|
47
|
+
import { setupSearchFields } from '@56os/search-fields';
|
|
48
|
+
setupSearchFields({
|
|
49
|
+
userTableConfigApi: { getConfigList, saveConfig },
|
|
50
|
+
customerSelectComponent: CustomerSelect
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`CurrencyInput` **无需** `setupUiComponents`。
|
|
55
|
+
|
|
56
|
+
## CustomerSelect
|
|
57
|
+
|
|
58
|
+
| prop | 说明 |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `partyType` | 1 供应商 / 2 客户 / 3 服务商 / 4 车队 |
|
|
61
|
+
| `labelMode` | `fullName` / `shortName` |
|
|
62
|
+
| `officeId` | 归属公司(仅供应商/客户) |
|
|
63
|
+
| `unitType` | 客户定价类型收窄 |
|
|
64
|
+
|
|
65
|
+
子应用可将原 `src/components/common/CustomerSelect.vue` 改为薄 re-export:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
export { CustomerSelect as default } from '@56os/ui-components';
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## CurrencyInput
|
|
72
|
+
|
|
73
|
+
金额 + 币种选择:`¥` 前缀、千分位展示、小数位限制、右侧币种下拉。
|
|
74
|
+
|
|
75
|
+
| prop | 说明 |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `modelValue` | 金额(原始数字串,无千分位) |
|
|
78
|
+
| `currencyType` | 币种 value |
|
|
79
|
+
| `currencyTypeList` | `{ label, value, remarks }`,`remarks` 为货币符号 |
|
|
80
|
+
| `decimalPlaces` | 失焦补齐小数位;输入过程默认最多 2 位 |
|
|
81
|
+
| `disabled` / `readonly` / `currencyDisabled` | 禁用 / 只读金额 / 禁用币种 |
|
|
82
|
+
|
|
83
|
+
```vue
|
|
84
|
+
<CurrencyInput
|
|
85
|
+
v-model="row.cost"
|
|
86
|
+
v-model:currency-type="row.costCurrencyType"
|
|
87
|
+
:currency-type-list="dict.currency_type"
|
|
88
|
+
placeholder="请输入成本单价"
|
|
89
|
+
/>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
子应用可将原 `src/components/common/CurrencyInput.vue` 改为薄 re-export:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
export { CurrencyInput as default } from '@56os/ui-components';
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 版本
|
|
99
|
+
|
|
100
|
+
- `0.1.0` 首发:CustomerSelect + setupUiComponents
|
|
101
|
+
- `0.2.0`:新增 CurrencyInput(无 `$filter` 依赖)
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@56os/ui-components",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "56os 通用 Vue 表单控件:CustomerSelect、CurrencyInput 等;API 经 setupUiComponents 注入",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"module": "./src/index.ts",
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/index.ts",
|
|
12
|
+
"import": "./src/index.ts",
|
|
13
|
+
"default": "./src/index.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"src",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": [
|
|
21
|
+
"**/*.vue",
|
|
22
|
+
"**/*.css"
|
|
23
|
+
],
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"element-plus": "^2.7.0",
|
|
26
|
+
"vue": "^3.4.0"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"56os",
|
|
30
|
+
"ui-components",
|
|
31
|
+
"vue3",
|
|
32
|
+
"element-plus",
|
|
33
|
+
"CustomerSelect",
|
|
34
|
+
"CurrencyInput"
|
|
35
|
+
],
|
|
36
|
+
"license": "UNLICENSED",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"registry": "https://registry.npmjs.org/"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- 货币输入框:符号走 prefix,输入区只编数字,避免光标在末尾删不掉 -->
|
|
3
|
+
<el-input
|
|
4
|
+
:key="`currency-${currencyType}-${forceUpdate}`"
|
|
5
|
+
ref="inputRef"
|
|
6
|
+
:placeholder="placeholder"
|
|
7
|
+
:model-value="displayValue"
|
|
8
|
+
:disabled="disabled"
|
|
9
|
+
:readonly="readonly"
|
|
10
|
+
@focus="handleFocus"
|
|
11
|
+
@blur="handleBlur"
|
|
12
|
+
@update:model-value="handleInputChange"
|
|
13
|
+
>
|
|
14
|
+
<template v-if="currencySymbol" #prefix>
|
|
15
|
+
<span class="currency-prefix">{{ currencySymbol }}</span>
|
|
16
|
+
</template>
|
|
17
|
+
<template #append>
|
|
18
|
+
<el-select
|
|
19
|
+
:model-value="String(currencyType)"
|
|
20
|
+
:disabled="currencyDisabled"
|
|
21
|
+
placeholder="请选择"
|
|
22
|
+
@update:model-value="handleCurrencyChange"
|
|
23
|
+
>
|
|
24
|
+
<el-option
|
|
25
|
+
v-for="item in currencyTypeList"
|
|
26
|
+
:key="item.value"
|
|
27
|
+
:label="item.label"
|
|
28
|
+
:value="String(item.value)"
|
|
29
|
+
></el-option>
|
|
30
|
+
</el-select>
|
|
31
|
+
</template>
|
|
32
|
+
</el-input>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
export default {
|
|
37
|
+
name: 'CurrencyInput',
|
|
38
|
+
props: {
|
|
39
|
+
modelValue: {
|
|
40
|
+
type: [String, Number],
|
|
41
|
+
default: ''
|
|
42
|
+
},
|
|
43
|
+
currencyType: {
|
|
44
|
+
type: [String, Number],
|
|
45
|
+
default: '1'
|
|
46
|
+
},
|
|
47
|
+
placeholder: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: '请输入'
|
|
50
|
+
},
|
|
51
|
+
currencyTypeList: {
|
|
52
|
+
type: Array,
|
|
53
|
+
default: () => []
|
|
54
|
+
},
|
|
55
|
+
disabled: {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
default: false
|
|
58
|
+
},
|
|
59
|
+
/** 只读:可点击聚焦(用于多段落点开浮窗),不可手输金额 */
|
|
60
|
+
readonly: {
|
|
61
|
+
type: Boolean,
|
|
62
|
+
default: false
|
|
63
|
+
},
|
|
64
|
+
currencyDisabled: {
|
|
65
|
+
type: Boolean,
|
|
66
|
+
default: false
|
|
67
|
+
},
|
|
68
|
+
decimalPlaces: {
|
|
69
|
+
type: Number,
|
|
70
|
+
default: null
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
emits: ['update:modelValue', 'update:currencyType'],
|
|
74
|
+
data() {
|
|
75
|
+
return {
|
|
76
|
+
forceUpdate: 0,
|
|
77
|
+
focused: false,
|
|
78
|
+
editingValue: ''
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
computed: {
|
|
82
|
+
/** 币种符号:读 currencyTypeList[].remarks,不依赖业务仓 $filter */
|
|
83
|
+
currencySymbol() {
|
|
84
|
+
const list = this.currencyTypeList || [];
|
|
85
|
+
const hit = list.find((item) => String(item?.value) === String(this.currencyType));
|
|
86
|
+
return hit?.remarks || '';
|
|
87
|
+
},
|
|
88
|
+
/** 聚焦时展示可编辑数字;失焦时展示千分位(及小数位) */
|
|
89
|
+
displayValue() {
|
|
90
|
+
if (this.focused) {
|
|
91
|
+
return this.editingValue;
|
|
92
|
+
}
|
|
93
|
+
return this.formatAmount(this.parseCurrency(this.modelValue));
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
watch: {
|
|
97
|
+
currencyType(newVal, oldVal) {
|
|
98
|
+
if (newVal !== oldVal) {
|
|
99
|
+
this.forceUpdate += 1;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
modelValue(newVal) {
|
|
103
|
+
if (!this.focused) {
|
|
104
|
+
this.editingValue = this.parseCurrency(newVal);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
methods: {
|
|
109
|
+
maxDecimalPlaces() {
|
|
110
|
+
return this.decimalPlaces !== null && this.decimalPlaces !== undefined ? this.decimalPlaces : 2;
|
|
111
|
+
},
|
|
112
|
+
parseCurrency(value) {
|
|
113
|
+
if (value === '' || value === null || value === undefined) return '';
|
|
114
|
+
return String(value).replace(/[^\d.-]/g, '');
|
|
115
|
+
},
|
|
116
|
+
limitDecimalInput(value) {
|
|
117
|
+
let cleanValue = this.parseCurrency(value);
|
|
118
|
+
if (!cleanValue) return '';
|
|
119
|
+
|
|
120
|
+
const negative = cleanValue.startsWith('-');
|
|
121
|
+
if (negative) {
|
|
122
|
+
cleanValue = cleanValue.slice(1);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const firstDot = cleanValue.indexOf('.');
|
|
126
|
+
if (firstDot !== -1) {
|
|
127
|
+
cleanValue =
|
|
128
|
+
cleanValue.slice(0, firstDot + 1) + cleanValue.slice(firstDot + 1).replace(/\./g, '');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const maxDecimals = this.maxDecimalPlaces();
|
|
132
|
+
if (firstDot !== -1 && maxDecimals >= 0) {
|
|
133
|
+
const [integerPart, decimalPart = ''] = cleanValue.split('.');
|
|
134
|
+
cleanValue = `${integerPart}.${decimalPart.slice(0, maxDecimals)}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return negative ? `-${cleanValue}` : cleanValue;
|
|
138
|
+
},
|
|
139
|
+
formatAmount(value) {
|
|
140
|
+
const cleanValue = this.parseCurrency(value);
|
|
141
|
+
if (!cleanValue) return '';
|
|
142
|
+
const shouldFixedDecimal = this.decimalPlaces !== null && this.decimalPlaces !== undefined;
|
|
143
|
+
const amount = shouldFixedDecimal ? this.toFixedDecimal(cleanValue) : cleanValue;
|
|
144
|
+
const [integerPart, decimalPart] = String(amount).split('.');
|
|
145
|
+
const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
146
|
+
return decimalPart === undefined ? formattedInteger : `${formattedInteger}.${decimalPart}`;
|
|
147
|
+
},
|
|
148
|
+
toFixedDecimal(value) {
|
|
149
|
+
const amount = Number(value);
|
|
150
|
+
if (!Number.isFinite(amount)) return value;
|
|
151
|
+
return amount.toFixed(this.decimalPlaces);
|
|
152
|
+
},
|
|
153
|
+
handleFocus() {
|
|
154
|
+
this.focused = true;
|
|
155
|
+
this.editingValue = this.limitDecimalInput(this.modelValue);
|
|
156
|
+
},
|
|
157
|
+
handleBlur() {
|
|
158
|
+
this.focused = false;
|
|
159
|
+
const cleanValue = this.limitDecimalInput(this.editingValue);
|
|
160
|
+
if (cleanValue !== '' && this.decimalPlaces !== null && this.decimalPlaces !== undefined) {
|
|
161
|
+
const fixed = this.toFixedDecimal(cleanValue);
|
|
162
|
+
this.editingValue = fixed;
|
|
163
|
+
this.$emit('update:modelValue', fixed);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
this.editingValue = cleanValue;
|
|
167
|
+
this.$emit('update:modelValue', cleanValue);
|
|
168
|
+
},
|
|
169
|
+
handleInputChange(value) {
|
|
170
|
+
const cleanValue = this.limitDecimalInput(value);
|
|
171
|
+
this.editingValue = cleanValue;
|
|
172
|
+
this.$emit('update:modelValue', cleanValue);
|
|
173
|
+
},
|
|
174
|
+
handleCurrencyChange(value) {
|
|
175
|
+
this.$emit('update:currencyType', String(value));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
</script>
|
|
180
|
+
|
|
181
|
+
<style scoped>
|
|
182
|
+
.currency-prefix {
|
|
183
|
+
color: var(--el-text-color-regular);
|
|
184
|
+
margin-right: 2px;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
:deep(.el-input-group__append .el-select) {
|
|
188
|
+
width: 100px !important;
|
|
189
|
+
}
|
|
190
|
+
</style>
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- 客商/车队名称下拉:API 经 setupUiComponents 注入;选项溢出悬停展示全文 -->
|
|
3
|
+
<el-select-v2
|
|
4
|
+
:key="selectRenderKey"
|
|
5
|
+
v-model="innerValue"
|
|
6
|
+
filterable
|
|
7
|
+
remote
|
|
8
|
+
:clearable="clearable"
|
|
9
|
+
:disabled="disabled"
|
|
10
|
+
:options="selectOptions"
|
|
11
|
+
:props="{ label: 'label', value: 'value' }"
|
|
12
|
+
:loading="loading"
|
|
13
|
+
:remote-method="onRemoteMethod"
|
|
14
|
+
:placeholder="placeholder"
|
|
15
|
+
style="width: 100%"
|
|
16
|
+
@change="onChange"
|
|
17
|
+
@clear="onClear"
|
|
18
|
+
>
|
|
19
|
+
<template #default="{ item }">
|
|
20
|
+
<el-tooltip
|
|
21
|
+
:content="item.label"
|
|
22
|
+
placement="right"
|
|
23
|
+
:show-after="300"
|
|
24
|
+
:disabled="!item.label"
|
|
25
|
+
>
|
|
26
|
+
<span class="customer-select-option-label">{{ item.label }}</span>
|
|
27
|
+
</el-tooltip>
|
|
28
|
+
</template>
|
|
29
|
+
</el-select-v2>
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script setup lang="ts">
|
|
33
|
+
import { computed, onMounted, ref, watch } from 'vue';
|
|
34
|
+
import { getCustomerSelectApis } from '../setup';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 客商/车队名称下拉
|
|
38
|
+
* partyType:1 供应商 / 2 客户 / 3 服务商 / 4 车队
|
|
39
|
+
* labelMode:fullName → 接口 type=1;shortName → type=2
|
|
40
|
+
* 出参统一 { label, value }
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
interface NameSelectItem {
|
|
44
|
+
label?: string;
|
|
45
|
+
value?: string | number;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface SelectOption {
|
|
50
|
+
label: string;
|
|
51
|
+
value: string | number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 1 供应商 2 客户 3 服务商 4 车队 */
|
|
55
|
+
type PartyType = 1 | 2 | 3 | 4;
|
|
56
|
+
|
|
57
|
+
interface Props {
|
|
58
|
+
modelValue?: string | number | '';
|
|
59
|
+
partyType?: PartyType;
|
|
60
|
+
labelMode?: 'fullName' | 'shortName';
|
|
61
|
+
/** 可选:自定义远程(覆盖内置注入接口) */
|
|
62
|
+
remoteMethod?: (query: string) => Promise<NameSelectItem[]>;
|
|
63
|
+
pageSize?: number;
|
|
64
|
+
placeholder?: string;
|
|
65
|
+
clearable?: boolean;
|
|
66
|
+
disabled?: boolean;
|
|
67
|
+
/** 归属公司 id:仅 1 供应商 / 2 客户 生效;空表示按登录身份范围 */
|
|
68
|
+
officeId?: string | number | '';
|
|
69
|
+
/** 客户定价类型:0 档位定价 / 1 单一客户定价;仅 2 客户 生效,空表示不收窄 */
|
|
70
|
+
unitType?: string | number | '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
74
|
+
modelValue: '',
|
|
75
|
+
partyType: 3,
|
|
76
|
+
labelMode: 'fullName',
|
|
77
|
+
pageSize: 50,
|
|
78
|
+
placeholder: '请选择',
|
|
79
|
+
clearable: true,
|
|
80
|
+
disabled: false,
|
|
81
|
+
officeId: '',
|
|
82
|
+
unitType: ''
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const emit = defineEmits<{
|
|
86
|
+
'update:modelValue': [value: string | number | ''];
|
|
87
|
+
change: [value: string | number | '', raw?: NameSelectItem];
|
|
88
|
+
}>();
|
|
89
|
+
|
|
90
|
+
const loading = ref(false);
|
|
91
|
+
const selectOptions = ref<SelectOption[]>([]);
|
|
92
|
+
const rawList = ref<NameSelectItem[]>([]);
|
|
93
|
+
/** options 异步补齐后递增,强制 el-select-v2 重算展示文案 */
|
|
94
|
+
const selectRenderKey = ref(0);
|
|
95
|
+
let remoteTimer: ReturnType<typeof setTimeout> | null = null;
|
|
96
|
+
let fetchSeq = 0;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 统一主体 id 为 string。
|
|
100
|
+
* el-select-v2 用 === 匹配;接口 value 常为 number、页面常为 string。
|
|
101
|
+
*/
|
|
102
|
+
const normalizeSelectId = (val: string | number | '' | null | undefined): string => {
|
|
103
|
+
if (val === '' || val === null || val === undefined) {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
return String(val);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const innerValue = computed({
|
|
110
|
+
get: () => normalizeSelectId(props.modelValue),
|
|
111
|
+
set: (val: string | number | '') => {
|
|
112
|
+
emit('update:modelValue', normalizeSelectId(val));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/** 全称 type=1,简称 type=2 */
|
|
117
|
+
const nameType = computed(() => (props.labelMode === 'shortName' ? 2 : 1));
|
|
118
|
+
|
|
119
|
+
/** 解析 TableDataInfo / 包装结构中的 rows */
|
|
120
|
+
const extractRows = (res: any): NameSelectItem[] => {
|
|
121
|
+
if (Array.isArray(res?.rows)) return res.rows;
|
|
122
|
+
if (Array.isArray(res?.data?.rows)) return res.data.rows;
|
|
123
|
+
if (Array.isArray(res?.data)) return res.data;
|
|
124
|
+
if (Array.isArray(res)) return res;
|
|
125
|
+
return [];
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** 仅供应商/客户支持按归属公司收窄 */
|
|
129
|
+
const withOffice = computed(() => props.partyType === 1 || props.partyType === 2);
|
|
130
|
+
|
|
131
|
+
const fetchNameSelectPage = async (
|
|
132
|
+
keywords: string,
|
|
133
|
+
extra: Record<string, unknown> = {}
|
|
134
|
+
): Promise<NameSelectItem[]> => {
|
|
135
|
+
const apis = getCustomerSelectApis();
|
|
136
|
+
const officeId = props.officeId;
|
|
137
|
+
const needOffice = withOffice.value && officeId !== '' && officeId !== null && officeId !== undefined;
|
|
138
|
+
const officeParams = needOffice ? { officeId } : {};
|
|
139
|
+
const unitType = props.unitType;
|
|
140
|
+
const needUnitType = props.partyType === 2 && unitType !== '' && unitType !== null && unitType !== undefined;
|
|
141
|
+
const unitTypeParams = needUnitType ? { unitType } : {};
|
|
142
|
+
const params = {
|
|
143
|
+
type: nameType.value,
|
|
144
|
+
keywords: keywords || undefined,
|
|
145
|
+
pageNum: 1,
|
|
146
|
+
pageSize: props.pageSize,
|
|
147
|
+
...officeParams,
|
|
148
|
+
...unitTypeParams,
|
|
149
|
+
...extra
|
|
150
|
+
};
|
|
151
|
+
let res: unknown;
|
|
152
|
+
if (props.partyType === 1) {
|
|
153
|
+
res = await apis.supplierNameSelectPage(params);
|
|
154
|
+
} else if (props.partyType === 2) {
|
|
155
|
+
res = await apis.customerNameSelectPage(params);
|
|
156
|
+
} else if (props.partyType === 4) {
|
|
157
|
+
res = await apis.fleetNameSelectPage(params);
|
|
158
|
+
} else {
|
|
159
|
+
res = await apis.entSupplierNameSelectPage(params);
|
|
160
|
+
}
|
|
161
|
+
return extractRows(res);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const mapToOptions = (list: NameSelectItem[]): SelectOption[] => {
|
|
165
|
+
return list
|
|
166
|
+
.filter((item) => item.value !== undefined && item.value !== null && item.value !== '')
|
|
167
|
+
.map((item) => ({
|
|
168
|
+
label: String(item.label ?? ''),
|
|
169
|
+
value: normalizeSelectId(item.value as string | number)
|
|
170
|
+
}));
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const ensureSelectedOption = (next: SelectOption[]): SelectOption[] => {
|
|
174
|
+
const selectedVal = normalizeSelectId(props.modelValue);
|
|
175
|
+
if (!selectedVal) {
|
|
176
|
+
return next;
|
|
177
|
+
}
|
|
178
|
+
const aligned = next.map((item) =>
|
|
179
|
+
String(item.value) === selectedVal ? { ...item, value: selectedVal } : item
|
|
180
|
+
);
|
|
181
|
+
const exists = aligned.some((item) => item.value === selectedVal);
|
|
182
|
+
if (exists) return aligned;
|
|
183
|
+
const prev = selectOptions.value.find((item) => String(item.value) === selectedVal);
|
|
184
|
+
if (prev) return [{ ...prev, value: selectedVal }, ...aligned];
|
|
185
|
+
return aligned;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const loadOptions = async (query: string) => {
|
|
189
|
+
const seq = ++fetchSeq;
|
|
190
|
+
const keyword = (query || '').trim();
|
|
191
|
+
const showLoading = selectOptions.value.length === 0;
|
|
192
|
+
if (showLoading) {
|
|
193
|
+
loading.value = true;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
let list: NameSelectItem[] = [];
|
|
197
|
+
if (typeof props.remoteMethod === 'function') {
|
|
198
|
+
list = await props.remoteMethod(query || '');
|
|
199
|
+
list = Array.isArray(list) ? list : [];
|
|
200
|
+
} else {
|
|
201
|
+
list = await fetchNameSelectPage(keyword);
|
|
202
|
+
}
|
|
203
|
+
if (seq !== fetchSeq) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
rawList.value = list;
|
|
207
|
+
selectOptions.value = ensureSelectedOption(mapToOptions(list));
|
|
208
|
+
} catch {
|
|
209
|
+
if (seq !== fetchSeq) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
selectOptions.value = ensureSelectedOption([]);
|
|
213
|
+
} finally {
|
|
214
|
+
if (seq === fetchSeq) {
|
|
215
|
+
loading.value = false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const onRemoteMethod = (query: string) => {
|
|
221
|
+
if (remoteTimer) {
|
|
222
|
+
clearTimeout(remoteTimer);
|
|
223
|
+
remoteTimer = null;
|
|
224
|
+
}
|
|
225
|
+
const keyword = (query || '').trim();
|
|
226
|
+
if (!keyword) {
|
|
227
|
+
loadOptions('');
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
remoteTimer = setTimeout(() => loadOptions(keyword), 300);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const hasOption = (val: string | number | '' | null | undefined) => {
|
|
234
|
+
if (val === '' || val === null || val === undefined) {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
return selectOptions.value.some((item) => String(item.value) === String(val));
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const echoSelected = async () => {
|
|
241
|
+
if (props.modelValue === '' || props.modelValue == null) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const list = await fetchNameSelectPage('', { id: props.modelValue });
|
|
245
|
+
const mapped = mapToOptions(list);
|
|
246
|
+
const echoIds = new Set(mapped.map((item) => String(item.value)));
|
|
247
|
+
rawList.value = [
|
|
248
|
+
...list,
|
|
249
|
+
...rawList.value.filter((item) => !echoIds.has(String(item.value ?? '')))
|
|
250
|
+
];
|
|
251
|
+
const merged = [
|
|
252
|
+
...mapped,
|
|
253
|
+
...selectOptions.value.filter((item) => !echoIds.has(String(item.value)))
|
|
254
|
+
];
|
|
255
|
+
const beforeHas = hasOption(props.modelValue);
|
|
256
|
+
selectOptions.value = ensureSelectedOption(merged);
|
|
257
|
+
if (!beforeHas && mapped.some((item) => String(item.value) === String(props.modelValue))) {
|
|
258
|
+
selectRenderKey.value += 1;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const echoIfMissing = () => {
|
|
263
|
+
const val = props.modelValue;
|
|
264
|
+
if (val === '' || val == null) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (!hasOption(val)) {
|
|
268
|
+
echoSelected();
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const onChange = (value: string | number | '') => {
|
|
273
|
+
const normalized = normalizeSelectId(value);
|
|
274
|
+
const raw = rawList.value.find((item) => String(item.value) === normalized);
|
|
275
|
+
emit('change', normalized, raw);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const onClear = () => {
|
|
279
|
+
emit('update:modelValue', '');
|
|
280
|
+
emit('change', '');
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
watch(
|
|
284
|
+
() => [props.labelMode, props.partyType, props.officeId, props.unitType],
|
|
285
|
+
() => {
|
|
286
|
+
selectOptions.value = [];
|
|
287
|
+
if (props.modelValue !== '' && props.modelValue != null) {
|
|
288
|
+
echoSelected();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
watch(
|
|
294
|
+
() => props.modelValue,
|
|
295
|
+
(val) => {
|
|
296
|
+
if (val === '' || val == null) {
|
|
297
|
+
selectOptions.value = [];
|
|
298
|
+
rawList.value = [];
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
echoIfMissing();
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
onMounted(() => {
|
|
306
|
+
echoSelected();
|
|
307
|
+
});
|
|
308
|
+
</script>
|
|
309
|
+
|
|
310
|
+
<style lang="scss" scoped>
|
|
311
|
+
.customer-select-option-label {
|
|
312
|
+
display: inline-block;
|
|
313
|
+
max-width: 100%;
|
|
314
|
+
overflow: hidden;
|
|
315
|
+
text-overflow: ellipsis;
|
|
316
|
+
white-space: nowrap;
|
|
317
|
+
vertical-align: bottom;
|
|
318
|
+
}
|
|
319
|
+
</style>
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { setupUiComponents, getCustomerSelectApis } from './setup';
|
|
2
|
+
export type {
|
|
3
|
+
CustomerSelectApis,
|
|
4
|
+
CustomerNameSelectParams,
|
|
5
|
+
SetupUiComponentsOptions
|
|
6
|
+
} from './setup';
|
|
7
|
+
|
|
8
|
+
export { default as CustomerSelect } from './components/CustomerSelect.vue';
|
|
9
|
+
export { default as CurrencyInput } from './components/CurrencyInput.vue';
|
package/src/setup.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** nameSelectPage 类接口入参(与现网仓库 / 客商接口对齐) */
|
|
2
|
+
export type CustomerNameSelectParams = Record<string, unknown>;
|
|
3
|
+
|
|
4
|
+
/** 各主体名称分页接口(子应用注入,包内不绑 @/api) */
|
|
5
|
+
export interface CustomerSelectApis {
|
|
6
|
+
customerNameSelectPage: (params: CustomerNameSelectParams) => Promise<unknown>;
|
|
7
|
+
supplierNameSelectPage: (params: CustomerNameSelectParams) => Promise<unknown>;
|
|
8
|
+
entSupplierNameSelectPage: (params: CustomerNameSelectParams) => Promise<unknown>;
|
|
9
|
+
fleetNameSelectPage: (params: CustomerNameSelectParams) => Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SetupUiComponentsOptions {
|
|
13
|
+
customerSelectApis: CustomerSelectApis;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let customerSelectApis: CustomerSelectApis | null = null;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 应用启动时注入客商下拉等 API。
|
|
20
|
+
* 包内禁止写死任一业务仓的 `@/api`。
|
|
21
|
+
*/
|
|
22
|
+
export function setupUiComponents(options: SetupUiComponentsOptions) {
|
|
23
|
+
const apis = options?.customerSelectApis;
|
|
24
|
+
if (
|
|
25
|
+
!apis?.customerNameSelectPage ||
|
|
26
|
+
!apis?.supplierNameSelectPage ||
|
|
27
|
+
!apis?.entSupplierNameSelectPage ||
|
|
28
|
+
!apis?.fleetNameSelectPage
|
|
29
|
+
) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
'[@56os/ui-components] setupUiComponents 需要传入 customerSelectApis 四套 nameSelectPage'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
customerSelectApis = apis;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getCustomerSelectApis(): CustomerSelectApis {
|
|
38
|
+
if (!customerSelectApis) {
|
|
39
|
+
throw new Error('[@56os/ui-components] 请先调用 setupUiComponents 注入 customerSelectApis');
|
|
40
|
+
}
|
|
41
|
+
return customerSelectApis;
|
|
42
|
+
}
|