Skip to content

Commit a9f8c59

Browse files
authored
多租户问题修复 (#8388)
* fix: 用户选择器后更新不回显 --bug=140528153 * fix: 运营租户/普通租户-自定义用户字段的默认值编辑态和查看态显示的是不一致的 --bug=140528153 * fix: 主机自动应用用户类型字段搜索异常 --bug=140531359 * 代码优化
1 parent aac1a08 commit a9f8c59

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

src/ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@blueking/bk-user-display-name": "^1.0.0",
20-
"@blueking/bk-user-selector": "^0.0.11",
20+
"@blueking/bk-user-selector": "^0.0.23",
2121
"@blueking/bkui-library": "^0.0.0-beta.6",
2222
"@blueking/functional-dependency": "^0.0.1-beta.10",
2323
"@blueking/login-modal": "^1.0.0",

src/ui/src/components/model-manage/field-group/field-view.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
</div>
148148
<cmdb-property-value
149149
class="property-value"
150-
v-if="['organization','enumquote'].includes(field.bk_property_type)"
150+
v-if="['organization','enumquote', 'objuser'].includes(field.bk_property_type)"
151151
:value="defaultValue"
152152
:property="field">
153153
</cmdb-property-value>

src/ui/src/views/host-apply/children/search-select-mix.vue

+46-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
:strink="false"
2323
v-model.trim="searchValue"
2424
:placeholder="$t('关键字/字段值')"
25+
:remote-method="fetchRemoteOptions"
26+
@input-change="handleInputChange"
2527
@change="handleChange"
2628
@menu-select="handleMenuSelect"
2729
@key-enter="handleKeyEnter"
@@ -39,13 +41,15 @@
3941
import has from 'has'
4042
import { CONFIG_MODE } from '@/service/service-template/index.js'
4143
import { PROPERTY_TYPES } from '@/dictionary/property-constants'
44+
import useSearchUser from '@/hooks/use-search-user'
4245

4346
export default {
4447
props: {
4548
mode: String
4649
},
4750
data() {
4851
return {
52+
isTyeing: false,
4953
showClear: false,
5054
searchOptions: [],
5155
fullOptions: [],
@@ -87,6 +91,7 @@
8791
},
8892
created() {
8993
this.initOptions()
94+
this.userSearch = useSearchUser().search
9095
},
9196
mounted() {
9297
Bus.$on('host-apply-clear-search', (value) => {
@@ -95,30 +100,49 @@
95100
})
96101
},
97102
methods: {
103+
async fetchRemoteOptions(val, menu) {
104+
// 根据具体类型走具体的远程方法拉取options
105+
const fetchs = {
106+
[PROPERTY_TYPES.OBJUSER]: this.fetchMember
107+
}
108+
return fetchs[menu.type](val, menu)
109+
},
110+
async fetchMember(val, menu) {
111+
if (!this.isTyeing || val?.length < 2 || val === `${menu.name}:`) {
112+
return []
113+
}
114+
const result = await this.userSearch(val)
115+
return result
116+
},
98117
async initOptions() {
99118
const availableProperties = this.configPropertyList.filter(property => property.host_apply_enabled)
100119
this.searchOptions = availableProperties.map((property) => {
101120
const type = property.bk_property_type
102121
const data = { id: property.id, name: property.bk_property_name, type, disabled: false }
103-
if (type === 'enum') {
122+
if (type === PROPERTY_TYPES.ENUM) {
104123
// eslint-disable-next-line max-len
105124
data.children = (property.option || []).map(option => ({ id: option.id, name: option.name, disabled: false }))
106125
data.multiable = true
107-
} else if (type === 'list') {
126+
} else if (type === PROPERTY_TYPES.LIST) {
108127
data.children = (property.option || []).map(option => ({ id: option, name: option, disabled: false }))
109128
data.multiable = true
110-
} else if (type === 'timezone') {
129+
} else if (type === PROPERTY_TYPES.TIMEZONE) {
111130
data.children = TIMEZONE.map(timezone => ({ id: timezone, name: timezone, disabled: false }))
112131
data.multiable = true
113-
} else if (type === 'bool') {
132+
} else if (type === PROPERTY_TYPES.BOOL) {
114133
data.children = [{ id: true, name: 'true' }, { id: false, name: 'false' }]
134+
} else if (type === PROPERTY_TYPES.OBJUSER) {
135+
data.remote = true
115136
} else {
116137
data.children = []
117138
}
118139
return data
119140
})
120141
this.fullOptions = this.searchOptions.slice(0)
121142
},
143+
handleInputChange() {
144+
this.isTyeing = true
145+
},
122146
handleChange(values) {
123147
const keywords = values.filter(value => !has(value, 'type') && has(value, 'id'))
124148
if (keywords.length > 1) {
@@ -130,10 +154,12 @@
130154
this.currentMenu = null
131155
},
132156
handleFocus() {
157+
this.isTyeing = true
133158
this.showClear = true
134159
},
135160
handleBlur() {
136161
this.showClear = false
162+
this.isTyeing = false
137163
},
138164
handleClear() {
139165
this.searchValue = []
@@ -146,6 +172,20 @@
146172
handleSearch() {
147173
Bus.$emit(this.searchEventName, this.getSearchValue())
148174
},
175+
getSingleTypeVal(type, value) {
176+
let val = value.id
177+
switch (type) {
178+
case PROPERTY_TYPES.ENUM:
179+
val = value.name
180+
break
181+
case PROPERTY_TYPES.OBJUSER:
182+
val = value.username
183+
break
184+
default:
185+
break
186+
}
187+
return val
188+
},
149189
getSearchValue() {
150190
const params = {
151191
query_filter: {
@@ -164,8 +204,8 @@
164204
if (isAny) {
165205
rule.operator = 'exist'
166206
} else {
167-
// 对枚举类型特殊处理
168-
const val = item.type === PROPERTY_TYPES.ENUM ? value.name : value.id
207+
// 对枚举类型/用户类型特殊处理
208+
const val = this.getSingleTypeVal(item.type, value)
169209
rule.operator = 'contains'
170210
rule.value = String(val).trim()
171211
}

0 commit comments

Comments
 (0)