123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- <template>
- <el-dialog
- class="bs-dialog-wrap bs-el-dialog"
- :append-to-body="true"
- :before-close="handleClose"
- :title="dataForm.id!==''?'编辑标签':'新增标签'"
- :visible.sync="dialogFormVisible"
- :width="relVisible?'1100px':'450px'"
- >
- <el-row>
- <el-col :span="relVisible ? 8 : 24">
- <el-divider
- class="bs-el-divider"
- content-position="left"
- >
- 属性信息
- </el-divider>
- <el-form
- ref="ruleForm"
- :model="dataForm"
- :rules="rules"
- label-position="right"
- label-width="90px"
- class="form-container"
- >
- <el-form-item
- label="标签名称"
- prop="labelName"
- >
- <el-input
- v-model="dataForm.labelName"
- class="bs-el-input"
- clearable
- placeholder="请输入标签名称"
- maxlength="200"
- />
- </el-form-item>
- <el-form-item
- label="标签类型"
- prop="labelType"
- >
- <el-select
- ref="searchSelect"
- v-model="dataForm.labelType"
- class="bs-el-select"
- popper-class="bs-el-select"
- allow-create
- clearable
- filterable
- placeholder="请选择或输入标签类型"
- @blur="selectBlur"
- @input.native="filterData"
- >
- <el-option
- v-for="(item,K) in labelTypeList"
- :key="K"
- :label="item"
- :value="item"
- />
- </el-select>
- </el-form-item>
- <el-form-item
- label="标签说明"
- prop="labelDesc"
- >
- <el-input
- v-model="dataForm.labelDesc"
- clearable
- placeholder="请输入标签说明"
- class="bs-el-input"
- type="text"
- />
- </el-form-item>
- </el-form>
- <el-divider
- class="bs-el-divider"
- content-position="left"
- >
- 关联数据集信息
- </el-divider>
- <el-form class="form-container">
- <el-form-item align="center">
- <el-tag effect="plain">
- 标签
- </el-tag>
- <span>—————</span>
- <el-button
- round
- size="mini"
- type="primary"
- @click="buildRel"
- >
- 添加关联
- </el-button>
- </el-form-item>
- </el-form>
- </el-col>
- <el-col
- v-if="relVisible"
- :span="8"
- >
- <div>
- <el-divider
- class="bs-el-divider"
- content-position="left"
- >
- 添加关联
- </el-divider>
- <div
- class="tree-box full-box--position"
- style="padding: 0 8px 24px 0"
- >
- <Tree
- ref="tree"
- :tree-data="categoryData"
- style="height: 300px;overflow: auto"
- @handleNodeClick="handleNodeClick"
- />
- </div>
- </div>
- </el-col>
- <el-col
- v-if="relVisible"
- :span="8"
- >
- <el-divider
- class="bs-el-divider"
- content-position="left"
- >
- 数据集列表
- </el-divider>
- <div class="bs-table-box">
- <el-table
- ref="mytable"
- class="bs-el-table"
- :data="datasetList"
- height="300"
- @select="handleSelect"
- @select-all="handleSelectionAll"
- >
- <el-table-column
- type="selection"
- width="55"
- />
- <el-table-column
- label="数据集名称"
- prop="name"
- show-overflow-tooltip
- />
- </el-table>
- </div>
- </el-col>
- </el-row>
- <span
- slot="footer"
- class="dialog-footer"
- >
- <el-button
- class="bs-el-button-default"
- @click="cancel"
- >
- 取消
- </el-button>
- <el-button
- type="primary"
- @click="submitForm('ruleForm')"
- >
- 确定
- </el-button>
- </span>
- </el-dialog>
- </template>
- <script>
- import { pageMixins } from 'packages/js/mixins/page'
- import Tree from './Tree'
- import { addOrUpdateLabel, checkRepeatLabel, getDataSetIdListByLabelId } from 'packages/js/utils/LabelConfigService'
- import { datasetList, getCategoryTree } from 'packages/js/utils/datasetConfigService'
- export default {
- name: 'LabelConfigAddOrUpdate',
- mixins: [pageMixins],
- data () {
- return {
- loading: false,
- datasetList: [],
- typeId: '',
- dataForm: {
- id: '',
- labelName: '',
- labelType: '',
- labelDesc: '',
- relList: []
- },
- dialogFormVisible: true,
- rules: {
- labelName: [
- { required: true, message: '标签名称不能为空', trigger: 'blur' },
- { validator: this.validateLabelName, trigger: 'blur' }
- ],
- labelType: [
- { required: true, message: '标签类型不能为空', trigger: 'change' }
- ]
- },
- // 分类树数据
- categoryData: [],
- relVisible: false,
- // 标签分类列表
- labelTypeList: [],
- // 选中的数据集id列表
- datasetIdList: []
- }
- },
- components: {
- Tree
- },
- watch: {
- 'dataForm.labelType': function (val) {
- if (val.length > 20) {
- this.dataForm.labelType = val.substring(0, 20)
- }
- },
- // datasetList变化时,根据datasetIdList设置其选中状态
- datasetList: {
- handler: function (val) {
- this.$nextTick(() => {
- if (this.$refs.mytable) {
- this.$refs.mytable.clearSelection()
- }
- this.datasetList.forEach((item) => {
- if (this.datasetIdList.includes(item.id)) {
- this.$refs.mytable.toggleRowSelection(item, true)
- }
- })
- })
- },
- deep: true
- }
- },
- methods: {
- /**
- * 初始化
- * @param row 标签信息
- */
- init (row) {
- this.dataForm.id = row ? row.id : ''
- this.dialogFormVisible = true
- if (row) {
- this.dataForm.id = row.id
- this.dataForm.labelName = row.labelName
- this.dataForm.labelType = row.labelType
- this.dataForm.labelDesc = row.labelDesc
- // 获取选中的数据集id列表
- getDataSetIdListByLabelId(row.id).then((list) => {
- this.datasetIdList = list
- this.buildRel()
- })
- }
- this.$nextTick(() => {
- this.getDataList()
- })
- },
- /**
- * 获取数据集列表
- */
- getDataList () {
- this.loading = true
- const params = {
- typeId: this.typeId
- }
- datasetList(params).then((list) => {
- this.datasetList = list
- if (!this.relVisible) {
- this.loading = false
- return
- }
- this.loading = false
- }).catch(() => {
- this.loading = false
- })
- },
- /**
- * 获取分类树
- */
- getTreeList () {
- getCategoryTree({ type: 'dataset' }).then((categoryTree) => {
- this.categoryData = categoryTree
- })
- },
- /**
- * 标签名称校验
- * @param rule
- * @param value
- * @param callback
- */
- validateLabelName (rule, value, callback) {
- checkRepeatLabel({ id: this.dataForm.id, labelName: this.dataForm.labelName }).then(repeat => {
- if (repeat) {
- callback(new Error('标签名称已存在'))
- } else {
- callback()
- }
- })
- },
- /**
- * 树节点点击事件
- * @param row
- * @param value
- */
- handleNodeClick (row, value) {
- this.$nextTick(() => {
- this.typeId = row.id
- this.getDataList()
- })
- },
- /**
- * 选中数据集
- * @param selection 选中的数据集列表
- * @param row 操作行
- */
- handleSelect (selection, row) {
- // 如row.id存在于datasetIdList中,则将其从datasetIdList中删除
- if (this.datasetIdList.includes(row.id)) {
- const index = this.datasetIdList.indexOf(row.id)
- if (index > -1) {
- this.datasetIdList.splice(index, 1)
- }
- return
- }
- // 如row.id不存在于datasetIdList中,则将其添加到datasetIdList中
- if (!this.datasetIdList.includes(row.id)) {
- this.datasetIdList.push(row.id)
- }
- },
- /**
- * 数据集全选
- * @param selection
- */
- handleSelectionAll (selection) {
- // 选中项为空,将datasetList中所有项从datasetIdList中删除
- if (selection.length === 0) {
- this.datasetList.forEach((dataset) => {
- const index = this.datasetIdList.indexOf(dataset.id)
- if (index > -1) {
- this.datasetIdList.splice(index, 1)
- }
- })
- return
- }
- // 选中项不为空,将datasetList中所有项添加到datasetIdList中
- if (selection.length > 0) {
- this.datasetList.forEach((dataset) => {
- if (!this.datasetIdList.includes(dataset.id)) {
- this.datasetIdList.push(dataset.id)
- }
- })
- }
- },
- /**
- * 表单关闭
- */
- handleClose () {
- this.$parent.addOrUpdateVisible = false
- },
- /**
- * 取消按钮
- */
- cancel () {
- this.dialogFormVisible = false
- this.$nextTick(() => {
- this.handleClose()
- })
- },
- /**
- * 提交按钮
- * @param formName
- */
- submitForm (formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- this.saveForm(true)
- } else {
- return false
- }
- })
- },
- /**
- * 保存标签信息
- * @param flag
- */
- saveForm (flag) {
- this.dataForm.relList = []
- this.datasetIdList.forEach(id => {
- const param = {
- datasetId: id,
- labelId: this.dataForm.id
- }
- this.dataForm.relList.push(param)
- })
- addOrUpdateLabel(this.dataForm).then((r) => {
- this.$message.success('保存成功')
- this.cancel()
- this.$parent.getDataList()
- // 更新一下类型
- this.$parent.getLabelType()
- })
- },
- /**
- * 添加关联按钮
- */
- buildRel () {
- this.relVisible = !this.relVisible
- if (this.relVisible) {
- this.getTreeList()
- this.$nextTick(() => {
- this.getDataList()
- })
- }
- },
- filterNode (value, data) {
- if (!value) return true
- return data.name.indexOf(value) !== -1
- },
- ellipsis (value, len) {
- if (!value) return ''
- if (value.length > len) {
- return value.slice(0, len) + '...'
- }
- return value
- },
- selectBlur (e) {
- this.dataForm.labelType = e.target.value
- },
- // 对输入字符串控制
- filterData () {
- // 此属性得到输入的文字
- const str = this.$refs.searchSelect.$data.selectedLabel
- // 控制的js
- if (str.length > 20) {
- this.$refs.searchSelect.$data.selectedLabel = str.substr(0, 20)
- }
- }
- }
- }
- </script>
- <style scoped>
- .el-col {
- height: 358px;
- }
- .tree-box {
- overflow-x: auto;
- }
- .form-container{
- padding: 0 8px;
- }
- ::v-deep .el-table{
- border: 1px solid transparent !important;
- }
- ::v-deep .el-table th.el-table__cell.is-leaf, .el-table td.el-table__cell{
- border-bottom: 1px solid transparent !important;
- }
- </style>
|