2023-08-24 17:15:41 +08:00
|
|
|
|
import { chartTableOrderOptionsMapping, storageKey, knowledgeCategoryValue } from '@/utils/constants'
|
2023-03-27 18:46:00 +08:00
|
|
|
|
import { getWidthByLanguage } from '@/utils/tools'
|
2023-05-29 13:00:28 +08:00
|
|
|
|
import { api } from '@/utils/api'
|
2023-08-24 17:15:41 +08:00
|
|
|
|
import axios from 'axios'
|
2021-06-11 10:00:22 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
props: {
|
|
|
|
|
|
tableData: {
|
|
|
|
|
|
type: Array
|
|
|
|
|
|
},
|
|
|
|
|
|
customTableTitle: {
|
|
|
|
|
|
type: Array
|
|
|
|
|
|
},
|
|
|
|
|
|
height: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
default: '100%'
|
|
|
|
|
|
},
|
|
|
|
|
|
api: {
|
|
|
|
|
|
type: String
|
|
|
|
|
|
},
|
|
|
|
|
|
tableId: {
|
|
|
|
|
|
type: String
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-06-23 15:57:34 +08:00
|
|
|
|
computed: {
|
|
|
|
|
|
customTableTitles () {
|
2023-03-27 18:46:00 +08:00
|
|
|
|
if (this.customTableTitle) {
|
2023-03-28 10:46:41 +08:00
|
|
|
|
// 设置列宽,避免分辨率过小时,文本显示省略号
|
2023-03-27 18:46:00 +08:00
|
|
|
|
this.getTableWidth(this.customTableTitle)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-23 15:57:34 +08:00
|
|
|
|
return this.customTableTitle.filter(item => item.show)
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
customTableTitle (n) {
|
|
|
|
|
|
if (n) {
|
|
|
|
|
|
setTimeout(() => {
|
2023-04-26 23:46:23 +08:00
|
|
|
|
if (this.$refs.dataTable) {
|
|
|
|
|
|
this.$refs.dataTable.doLayout()
|
|
|
|
|
|
}
|
2023-03-06 20:16:31 +08:00
|
|
|
|
}, 200)
|
2021-06-23 15:57:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2021-06-11 10:00:22 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2021-06-23 15:57:34 +08:00
|
|
|
|
operationWidth: '165', // 操作列宽
|
2023-06-16 17:51:08 +08:00
|
|
|
|
show: true,
|
|
|
|
|
|
isNoData: false
|
2021-06-11 10:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2023-06-16 17:51:08 +08:00
|
|
|
|
toggleLoading (loading) {
|
|
|
|
|
|
this.$emit('toggleLoading', loading)
|
|
|
|
|
|
},
|
2023-03-27 18:46:00 +08:00
|
|
|
|
getTableWidth (list) {
|
|
|
|
|
|
if (list && list.length > 0) {
|
|
|
|
|
|
const language = localStorage.getItem(storageKey.language)
|
|
|
|
|
|
// 文字所占宽度,一个英文字母占7px,中文16px
|
|
|
|
|
|
let num = getWidthByLanguage(language) || 7
|
|
|
|
|
|
if (language !== 'cn') {
|
|
|
|
|
|
num = num + 1 // 最后一位加空格
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
list.forEach((item, index) => {
|
2023-03-28 18:13:20 +08:00
|
|
|
|
if (item.label && item.label !== 'IP') {
|
2023-03-27 18:46:00 +08:00
|
|
|
|
let tempLength = 0
|
|
|
|
|
|
|
|
|
|
|
|
if (item.label.indexOf(' ') > -1) {
|
|
|
|
|
|
let tempArr = []
|
|
|
|
|
|
tempArr = item.label.split(' ')
|
|
|
|
|
|
tempLength = Math.max(...tempArr.map(el => el.length))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tempLength = item.label.length
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 宽度 = 最小不可拆分单词文字宽度 + 22的padding边距
|
|
|
|
|
|
const newWidth = (num * tempLength) + 22
|
|
|
|
|
|
|
|
|
|
|
|
// 为了避免没有minWidth这种情况
|
|
|
|
|
|
if (!item.minWidth) {
|
|
|
|
|
|
item.minWidth = newWidth
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 排序最后一位一般是'操作',或者是较长的字符,故不让其换行,宽度直接为字符宽度
|
|
|
|
|
|
if (index === list.length - 1) {
|
|
|
|
|
|
item.minWidth = (num * item.label.length) + 22
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 有排序的,额外添加24px的排序图标宽度
|
|
|
|
|
|
if (item.sortable) {
|
2023-04-19 16:25:55 +08:00
|
|
|
|
if (!item.initFlag) {
|
|
|
|
|
|
item.minWidth = item.minWidth + 32
|
|
|
|
|
|
}
|
|
|
|
|
|
// 避免customize多次点击save生成表格,导致width越来越大,保证初始化一次就确定宽度
|
|
|
|
|
|
item.initFlag = true
|
2023-03-28 18:13:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.minWidth < newWidth) {
|
|
|
|
|
|
item.minWidth = newWidth
|
|
|
|
|
|
} else if (item.width < item.minWidth) {
|
|
|
|
|
|
item.width = item.minWidth
|
2023-03-27 18:46:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-05-29 13:00:28 +08:00
|
|
|
|
changeStatus (status, id) {
|
2023-06-09 09:45:08 +08:00
|
|
|
|
if (id) {
|
2023-08-24 17:15:41 +08:00
|
|
|
|
axios.patch(api.knowledgeBaseEnable, { list: [{ knowledgeId: id, status: status }] }).then(response => {
|
|
|
|
|
|
console.info(response)
|
|
|
|
|
|
if (response.status === 200) {
|
2023-06-05 19:42:44 +08:00
|
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
|
2023-05-29 13:00:28 +08:00
|
|
|
|
} else {
|
2023-06-02 14:15:00 +08:00
|
|
|
|
console.error(response)
|
2023-08-24 17:15:41 +08:00
|
|
|
|
if (response.data.message) {
|
|
|
|
|
|
this.$message.error(response.data.message)
|
2023-06-02 14:15:00 +08:00
|
|
|
|
} else {
|
2023-08-01 17:58:27 +08:00
|
|
|
|
this.$message.error(this.$t('tip.somethingWentWrong'))
|
2023-06-02 14:15:00 +08:00
|
|
|
|
}
|
2023-05-29 13:00:28 +08:00
|
|
|
|
}
|
2023-06-05 19:42:44 +08:00
|
|
|
|
this.$emit('reload')
|
2023-06-02 14:15:00 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2023-05-29 13:00:28 +08:00
|
|
|
|
},
|
2023-06-08 17:17:41 +08:00
|
|
|
|
selectable (row, rowIndex) {
|
2023-08-24 17:15:41 +08:00
|
|
|
|
return row.isBuiltIn !== 1
|
2023-06-08 17:17:41 +08:00
|
|
|
|
},
|
2022-06-06 17:37:01 +08:00
|
|
|
|
tableOperation ([command, row]) {
|
2021-06-11 10:00:22 +08:00
|
|
|
|
switch (command) {
|
|
|
|
|
|
default:
|
2022-06-06 17:37:01 +08:00
|
|
|
|
this.$emit(command, row)
|
2021-06-11 10:00:22 +08:00
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
selectionChange (objs) {
|
|
|
|
|
|
this.$emit('selectionChange', objs)
|
|
|
|
|
|
},
|
2023-04-26 23:46:23 +08:00
|
|
|
|
checkboxStatusChange (isCheck, data) {
|
|
|
|
|
|
this.$emit('checkboxStatusChange', isCheck, data)
|
|
|
|
|
|
},
|
2021-06-11 10:00:22 +08:00
|
|
|
|
dragend () {
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.$refs.dataTable.doLayout()
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
tableDataSort (item) {
|
2023-03-08 17:35:22 +08:00
|
|
|
|
const orderBy = (item.order === 'descending' ? '-' : '') + (item.prop ? (chartTableOrderOptionsMapping[item.prop] || item.prop) : '')
|
2021-06-11 10:00:22 +08:00
|
|
|
|
this.$emit('orderBy', orderBy)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|