Skip to content

Commit

Permalink
fix: 共享到商店侧栏场景分类下拉框交互优化 --story=121000017
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 28175
  • Loading branch information
ywywZhou committed Dec 31, 2024
1 parent 156d014 commit 4dabd9b
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,9 @@
pipeline_template__name__icontains: this.flowName || undefined,
common: this.isCommon
}
const templateListData = await this.loadTemplateList(params)
const templateListData = this.isCommon
? await this.loadCommonTemplateList(params)
: await this.loadTemplateList(params)
if (add) {
this.templateList.push(...templateListData.results)
} else { // 搜索
Expand Down Expand Up @@ -540,9 +542,7 @@
try {
this.templateDataLoading = true
const params = { templateId: id, common: this.isCommon }
const templateData = this.isCommon
? await this.loadCommonTemplateList(params)
: await this.loadTemplateData(params)
const templateData = await this.loadTemplateData(params)
// 获取流程模板的通知配置
const { notify_receivers, notify_type } = templateData
this.notifyType = [notify_type.success.slice(0), notify_type.fail.slice(0)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<template>
<bk-select
ref="categorySelect"
:disabled="formData.type === 'update'"
v-model="formData.category"
:loading="loading"
:show-empty="!categoryList.length"
searchable
:remote-method="onCategorySearch"
@toggle="handleSelectToggle">
<div
slot="trigger"
class="bk-select-name category-select"
:data-placeholder="categorySelectPath ? '' : $t('请选择场景分类')">
{{ categorySelectPath }}
<i class="bk-select-angle bk-icon icon-angle-down"></i>
</div>
<template v-if="searchVal">
<bk-option
v-for="option in searchList"
:key="option.id"
:id="option.id"
:name="option.name">
</bk-option>
<p v-if="!searchList.length" class="search-empty-info">{{ $t('搜索结果为空') }}</p>
</template>
<bk-big-tree
v-else
ref="categoryTree"
:data="categoryList"
selectable
:show-link-line="false"
:show-icon="false"
:options="{ idKey: 'code_path' }"
:default-expanded-nodes="defaultExpandedNodes"
:default-selected-node="formData.category"
:before-select="(node) => !node.children.length"
@select-change="onCategorySelect">
</bk-big-tree>
</bk-select>
</template>
<script>
export default {
props: {
categoryList: {
type: Array,
default: () => ([])
},
loading: {
type: Boolean,
default: false
},
formData: {
type: Object,
default: () => ({})
}
},
data () {
return {
searchVal: '',
searchList: []
}
},
computed: {
categorySelectPath () {
return this.findPathByCodePath(this.categoryList, this.formData.category)
},
defaultExpandedNodes () {
return this.categoryList.map(item => item.code_path)
},
categoryFlattenList () {
return this.handleFlattenList(this.categoryList)
}
},
methods: {
onCategorySearch (val) {
this.searchVal = val
this.searchList = val
? this.categoryFlattenList.filter(item => item.name.toLowerCase().indexOf(val.toLowerCase()) > -1)
: []
},
onCategorySelect (node) {
this.formData.category = node.id
this.$refs.categorySelect.close()
},
handleFlattenList (data, parentPath = '') {
let result = []
data.forEach(item => {
const currentPath = parentPath ? `${parentPath}-${item.name}` : item.name
if (item.children && item.children.length > 0) {
result = result.concat(this.handleFlattenList(item.children, currentPath))
} else {
result.push({ id: item.code_path, name: currentPath })
}
})
return result
},
findPathByCodePath (categoryList, targetCodePath) {
const traverse = (node, path) => {
const currentPath = [...path, node.name]
if (node.code_path === targetCodePath) {
return currentPath
}
for (const child of node.children || []) {
const result = traverse(child, currentPath)
if (result) {
return result
}
}
return null
}
for (const rootNode of categoryList) {
const result = traverse(rootNode, [])
if (result) {
return result.join('-')
}
}
return null
},
handleSelectToggle () {
this.searchVal = ''
this.searchList = []
}
}
}
</script>
<style lang="scss" scoped>
.category-select::before {
position: absolute;
content: attr(data-placeholder);
color: #c4c6cc;
}
.search-empty-info {
margin: 15px 0;
text-align: center;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,11 @@
</p>
</bk-form-item>
<bk-form-item :label="$t('场景分类')" property="category" :required="true" :rules="rules.required">
<bk-select
:disabled="formData.type === 'update'"
v-model="formData.category"
<SharedCategorySelect
:loading="marketLoading"
:show-empty="!categoryList.length">
<div
slot="trigger"
class="bk-select-name category-select"
:data-placeholder="categorySelectPath ? '' : $t('请选择场景分类')">
{{ categorySelectPath }}
<i class="bk-select-angle bk-icon icon-angle-down"></i>
</div>
<bk-big-tree
ref="categoryTree"
:data="categoryList"
:selectable="true"
:show-link-line="false"
:show-icon="false"
:options="{
idKey: 'code_path'
}"
:before-select="(node) => !node.children.length"
@select-change="onCategorySelect">
</bk-big-tree>
</bk-select>
:category-list="categoryList"
:form-data="formData">
</SharedCategorySelect>
</bk-form-item>
<bk-form-item :label="$t('标签')" :desc="$t('场景使用者通过标签可以快速找到同一类场景')">
<SharedTagSelect
Expand Down Expand Up @@ -133,10 +113,12 @@
import tools from '@/utils/tools.js'
import { mapActions, mapState } from 'vuex'
import SharedTagSelect from './SharedTagSelect.vue'
import SharedCategorySelect from './SharedCategorySelect.vue'
import MarkdownEditor from './markdownEditor/editor.vue'
export default {
components: {
SharedTagSelect,
SharedCategorySelect,
MarkdownEditor
},
props: {
Expand Down Expand Up @@ -204,10 +186,7 @@
...mapState({
'infoBasicConfig': state => state.infoBasicConfig,
'username': state => state.username
}),
categorySelectPath () {
return this.findPathByCodePath(this.categoryList, this.formData.category)
}
})
},
watch: {
isShow (val) {
Expand Down Expand Up @@ -298,35 +277,6 @@
usage_content: { content }
})
},
onCategorySelect (node) {
this.formData.category = node.id
},
findPathByCodePath (categoryList, targetCodePath) {
const traverse = (node, path) => {
const currentPath = [...path, node.name]
if (node.code_path === targetCodePath) {
return currentPath
}
for (const child of node.children || []) {
const result = traverse(child, currentPath)
if (result) {
return result
}
}
return null
}
for (const rootNode of categoryList) {
const result = traverse(rootNode, [])
if (result) {
return result.join('/')
}
}
return null
},
onSave () {
this.$refs.formRef.validate().then(async result => {
try {
Expand Down Expand Up @@ -472,11 +422,6 @@
}
}
}
.category-select::before {
position: absolute;
content: attr(data-placeholder);
color: #c4c6cc;
}
.editor-container {
flex: 1;
.bk-form-content {
Expand Down

0 comments on commit 4dabd9b

Please sign in to comment.