index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div class="bm-main-box">
  3. <div class="flex items-center">
  4. <div class="bm-main-box-title">问答</div>
  5. </div>
  6. <CzrContent
  7. v-model:tableHead="state.query.head"
  8. @handleReset="onReset"
  9. @handleSearch="onSearch"
  10. >
  11. <template #tableTitle>
  12. <div class="flex gap-[var(--czr-gap)]">
  13. <CzrButton type="add" title="创建问题" @click="onAdd" />
  14. <CzrButton title="迁移" icon="move" @click="onKnowledge()" />
  15. <CzrButton type="del" title="删除" icon="czr_del" @click="onDel()" />
  16. </div>
  17. </template>
  18. <template #buttons>
  19. <div class="flex items-center gap-[var(--czr-gap)]">
  20. <CzrForm class="bm-filter" label-width="0px" @handleEnter="onSearch">
  21. <CzrFormColumn
  22. width="15.63rem"
  23. class="__czr-table-form-column"
  24. :span="24"
  25. label-width="0px"
  26. v-model:param="state.text"
  27. placeholder="按问答名称搜索"
  28. :prefix-icon="Search"
  29. />
  30. </CzrForm>
  31. </div>
  32. </template>
  33. <template #table>
  34. <CzrTable
  35. v-loading="state.query.loading"
  36. :data="state.query.result.data"
  37. :head="state.query.head"
  38. :total="state.query.result.total"
  39. :page="state.query.page.pageNum"
  40. :pageSize="state.query.page.pageSize"
  41. @handlePage="onPage"
  42. v-model:selected="state.query.selected"
  43. >
  44. <template #caozuo-column-value="{ scope }">
  45. <div class="__czr-table-operations">
  46. <CzrButton
  47. type="table"
  48. title="重命名"
  49. @click="onRename(scope.row)"
  50. />
  51. <CzrButton
  52. type="table"
  53. title="迁移"
  54. @click="onKnowledge(scope.row)"
  55. />
  56. <CzrButton type="table" title="编辑" @click="onEdit(scope.row)" />
  57. <CzrButton type="table-del" @click="onDel(scope.row)" />
  58. </div>
  59. </template>
  60. </CzrTable>
  61. </template>
  62. </CzrContent>
  63. <detailCom
  64. v-model:show="state.detail.show"
  65. :transfer="state.detail.transfer"
  66. @refresh="onSearch"
  67. />
  68. <renameCom
  69. v-model:show="state.rename.show"
  70. :transfer="state.rename.transfer"
  71. @refresh="onSearch"
  72. />
  73. <knowledgeSelectCom
  74. v-model:show="state.knowledge.show"
  75. :transfer="state.knowledge.transfer"
  76. @refresh="onSearch"
  77. />
  78. </div>
  79. </template>
  80. <script setup lang="ts">
  81. import {
  82. getCurrentInstance,
  83. inject,
  84. onMounted,
  85. reactive,
  86. ref,
  87. watch,
  88. } from 'vue'
  89. import { Search } from '@element-plus/icons-vue'
  90. import { debounce } from 'lodash'
  91. import { useDialogStore, useDictionaryStore } from '@/stores'
  92. import { ElMessage } from 'element-plus'
  93. import detailCom from './detail.vue'
  94. import renameCom from './rename.vue'
  95. import knowledgeSelectCom from '../document/knowledge-select.vue'
  96. import { qaGetQaPage, qaQaDocsDelete } from '@/api/modules/knowledge/qa'
  97. const DialogStore = useDialogStore()
  98. const DictionaryStore = useDictionaryStore()
  99. const emit = defineEmits([])
  100. const props = defineProps({
  101. knowledge: <any>{},
  102. })
  103. const { proxy }: any = getCurrentInstance()
  104. const ID = inject('ID')
  105. const state: any = reactive({
  106. text: '',
  107. query: {
  108. init: false,
  109. loading: false,
  110. head: [
  111. { value: 'name', label: '文件名称', show: true },
  112. {
  113. value: 'createTime',
  114. label: '创建时间',
  115. show: true,
  116. width: 180,
  117. datetime: true,
  118. },
  119. {
  120. value: 'updateTime',
  121. label: '更新时间',
  122. show: true,
  123. width: 180,
  124. datetime: true,
  125. },
  126. {
  127. value: 'caozuo',
  128. label: '操作',
  129. show: true,
  130. width: 300,
  131. fixed: 'right',
  132. popover: false,
  133. },
  134. ],
  135. page: {
  136. pageNum: 1,
  137. pageSize: 20,
  138. },
  139. form: {},
  140. formReal: {},
  141. result: {
  142. total: 0,
  143. data: [],
  144. },
  145. selected: [],
  146. },
  147. detail: {
  148. show: false,
  149. transfer: {},
  150. },
  151. rename: {
  152. show: false,
  153. transfer: {},
  154. },
  155. knowledge: {
  156. show: false,
  157. transfer: {},
  158. },
  159. })
  160. const setText = debounce((v) => {
  161. state.query.form.name = v
  162. }, 1000)
  163. watch(
  164. () => state.text,
  165. (n) => {
  166. setText(n)
  167. },
  168. )
  169. watch(
  170. () => state.query.form,
  171. (n) => {
  172. if (state.query.init) {
  173. onSearch()
  174. }
  175. },
  176. { deep: true },
  177. )
  178. const onPage = (pageNum, pageSize) => {
  179. setTimeout(() => {
  180. state.query.init = true
  181. }, 100)
  182. state.query.page = {
  183. pageNum: pageNum,
  184. pageSize: pageSize,
  185. }
  186. const params = {
  187. datasetId: ID,
  188. page: state.query.page.pageNum,
  189. size: state.query.page.pageSize,
  190. }
  191. // 添加表单参数
  192. for (const [k, v] of Object.entries(state.query.formReal)) {
  193. if (proxy.$czrUtil.isValue(v)) {
  194. params[k] = v
  195. }
  196. }
  197. state.query.loading = true
  198. qaGetQaPage(params)
  199. .then(({ data }: any) => {
  200. state.query.result.total = data.totalElements
  201. state.query.result.data = data.content
  202. })
  203. .catch(() => {})
  204. .finally(() => {
  205. state.query.loading = false
  206. })
  207. }
  208. const onSearch = () => {
  209. state.query.selected = []
  210. state.query.formReal = JSON.parse(JSON.stringify(state.query.form))
  211. onPage(1, state.query.page.pageSize)
  212. }
  213. const onReset = () => {
  214. state.query.page = {
  215. pageNum: 1,
  216. pageSize: 20,
  217. }
  218. state.query.form = {}
  219. onSearch()
  220. }
  221. const onAdd = () => {
  222. state.detail.transfer = {
  223. mode: 'add',
  224. ID: ID,
  225. }
  226. state.detail.show = true
  227. }
  228. const onEdit = (row) => {
  229. state.detail.transfer = {
  230. mode: 'edit',
  231. id: row.id,
  232. }
  233. state.detail.show = true
  234. }
  235. const onDel = (row: any = null) => {
  236. if (row) {
  237. DialogStore.confirm({
  238. title: '删除确认',
  239. content: `是否删除问答:${row.name}?<br/>请谨慎操作。`,
  240. onSubmit: () => {
  241. qaQaDocsDelete([row.id])
  242. .then(() => {
  243. ElMessage.success('删除成功!')
  244. })
  245. .catch(() => {})
  246. .finally(() => {
  247. onSearch()
  248. })
  249. },
  250. })
  251. } else {
  252. if (state.query.selected.length === 0) {
  253. ElMessage.warning('请至少选择一条记录!')
  254. return
  255. }
  256. DialogStore.confirm({
  257. title: '删除确认',
  258. content: `是否批量删除${state.query.selected.length}个问答?<br/>请谨慎操作。`,
  259. onSubmit: () => {
  260. qaQaDocsDelete(state.query.selected.map((v) => v.id))
  261. .then(() => {
  262. ElMessage.success('删除成功!')
  263. })
  264. .catch(() => {})
  265. .finally(() => {
  266. onSearch()
  267. })
  268. },
  269. })
  270. }
  271. }
  272. const onRename = (row) => {
  273. state.rename.transfer = {
  274. id: row.id,
  275. name: JSON.parse(JSON.stringify(row.name)),
  276. }
  277. state.rename.show = true
  278. }
  279. const onKnowledge = (row: any = null) => {
  280. if (row) {
  281. state.knowledge.transfer = {
  282. row: JSON.parse(JSON.stringify(row)),
  283. type: 'qa',
  284. }
  285. state.knowledge.show = true
  286. } else {
  287. if (state.query.selected.length === 0) {
  288. ElMessage.warning('请至少选择一条记录!')
  289. return
  290. }
  291. state.knowledge.transfer = {
  292. list: [...state.query.selected],
  293. type: 'qa',
  294. }
  295. state.knowledge.show = true
  296. }
  297. }
  298. onMounted(() => {
  299. initDictionary()
  300. onReset()
  301. })
  302. const initDictionary = () => {}
  303. </script>
  304. <style lang="scss" scoped>
  305. .knowledge {
  306. width: 100%;
  307. height: 11.81rem;
  308. background-image: url('@/assets/images/knowledge-item-bg.png');
  309. background-repeat: no-repeat;
  310. background-size: 100% 100%;
  311. padding: 1rem 1.5rem;
  312. }
  313. </style>