index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter"
  4. :leave-active-class="proxy?.animate.searchAnimate.leave">
  5. <div v-show="showSearch" class="mb-[10px]">
  6. <el-card shadow="hover" :style="{ marginTop: '10px', height: '60px' }">
  7. <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="45">
  8. <el-form-item label="问题" prop="question">
  9. <el-input v-model="queryParams.question" placeholder="请输入问题" clearable @keyup.enter="handleQuery"/>
  10. </el-form-item>
  11. <el-form-item label="创建" prop="createUser">
  12. <el-input v-model="queryParams.createUser" placeholder="请输入创建人" clearable
  13. @keyup.enter="handleQuery"/>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  17. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  18. <el-button type="primary" plain icon="Plus" @click="handleAdd"
  19. v-hasPermi="['device:difyDatasetsQuestion:add']">新增
  20. </el-button>
  21. </el-form-item>
  22. <el-form-item>
  23. <!-- <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()"
  24. v-hasPermi="['device:difyDatasetsQuestion:edit']">修改
  25. </el-button>
  26. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()"
  27. v-hasPermi="['device:difyDatasetsQuestion:remove']">删除
  28. </el-button>
  29. <el-button type="warning" plain icon="Download" @click="handleExport"
  30. v-hasPermi="['device:difyDatasetsQuestion:export']">导出
  31. </el-button>-->
  32. </el-form-item>
  33. </el-form>
  34. </el-card>
  35. </div>
  36. </transition>
  37. <el-card shadow="never">
  38. <el-table v-loading="loading" :data="difyDatasetsQuestionList" @selection-change="handleSelectionChange">
  39. <!-- <el-table-column type="selection" width="55" align="left"/>-->
  40. <el-table-column label="" align="left" prop="" width="10"/>
  41. <el-table-column label="ID" align="left" prop="id" v-if="true" width="180"/>
  42. <el-table-column label="问题" align="left" prop="question"/>
  43. <el-table-column label="回答" align="left" prop="answer"/>
  44. <el-table-column label="排序" align="center" prop="sort" width="100"/>
  45. <el-table-column label="属性" align="center" width="120">
  46. <template #default="scope">
  47. <dict-tag :options="smsb_question_properties" :value="scope.row.property" />
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="创建人" align="left" prop="createUser" width="150" :show-overflow-tooltip="true"/>
  51. <el-table-column label="创建时间" align="left" prop="createTime" width="160"/>
  52. <el-table-column label="操作" align="left" width="120" class-name="small-padding fixed-width">
  53. <template #default="scope">
  54. <el-tooltip content="修改" placement="top">
  55. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
  56. v-hasPermi="['device:difyDatasetsQuestion:edit']"></el-button>
  57. </el-tooltip>
  58. <el-tooltip content="删除" placement="top">
  59. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
  60. v-hasPermi="['device:difyDatasetsQuestion:remove']"></el-button>
  61. </el-tooltip>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
  66. v-model:limit="queryParams.pageSize" @pagination="getList"/>
  67. </el-card>
  68. <!-- 添加或修改Dify知识问答对话框 -->
  69. <el-dialog :title="dialog.title" v-model="dialog.visible" width="700px" append-to-body>
  70. <el-form ref="difyDatasetsQuestionFormRef" :model="form" :rules="rules" label-width="50px">
  71. <el-row :gutter="20">
  72. <el-col :span="12">
  73. <el-form-item label="序号" prop="sort">
  74. <el-input-number v-model="form.sort" controls-position="right" placeholder="请输入序号" :min="1" :max="100000"
  75. style="width: 180px" :maxlength="6"/>
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="12">
  79. <el-form-item label="属性" prop="property">
  80. <el-select v-model="form.property" placeholder="请选择属性">
  81. <el-option v-for="dict in smsb_question_properties" :key="dict.value" :label="dict.label"
  82. :value="parseInt(dict.value)"></el-option>
  83. </el-select>
  84. </el-form-item>
  85. </el-col>
  86. </el-row>
  87. <el-form-item label="问题" prop="question">
  88. <el-input v-model="form.question" placeholder="请输入问题"/>
  89. </el-form-item>
  90. <el-form-item label="回答" prop="answer">
  91. <el-input v-model="form.answer" type="textarea" placeholder="请输入内容" :rows="5"/>
  92. </el-form-item>
  93. </el-form>
  94. <template #footer>
  95. <div class="dialog-footer">
  96. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  97. <el-button @click="cancel">取 消</el-button>
  98. </div>
  99. </template>
  100. </el-dialog>
  101. </div>
  102. </template>
  103. <script setup name="DifyDatasetsQuestion" lang="ts">
  104. import {
  105. listDifyDatasetsQuestion,
  106. getDifyDatasetsQuestion,
  107. delDifyDatasetsQuestion,
  108. addDifyDatasetsQuestion,
  109. updateDifyDatasetsQuestion
  110. } from '@/api/smsb/device/difyDatasetsQuestion_index';
  111. import {
  112. DifyDatasetsQuestionVO,
  113. DifyDatasetsQuestionQuery,
  114. DifyDatasetsQuestionForm
  115. } from '@/api/smsb/device/difyDatasetsQuestion_types';
  116. const {proxy} = getCurrentInstance() as ComponentInternalInstance;
  117. const difyDatasetsQuestionList = ref<DifyDatasetsQuestionVO[]>([]);
  118. const buttonLoading = ref(false);
  119. const loading = ref(true);
  120. const showSearch = ref(true);
  121. const ids = ref<Array<string | number>>([]);
  122. const single = ref(true);
  123. const multiple = ref(true);
  124. const total = ref(0);
  125. const {
  126. smsb_question_properties,
  127. } =
  128. toRefs<any>(
  129. proxy?.useDict(
  130. 'smsb_question_properties',
  131. )
  132. );
  133. const queryFormRef = ref<ElFormInstance>();
  134. const difyDatasetsQuestionFormRef = ref<ElFormInstance>();
  135. const dialog = reactive<DialogOption>({
  136. visible: false,
  137. title: ''
  138. });
  139. const initFormData: DifyDatasetsQuestionForm = {
  140. id: undefined,
  141. question: undefined,
  142. answer: undefined,
  143. sort: 1,
  144. createUser: undefined,
  145. property: undefined,
  146. }
  147. const data = reactive<PageData<DifyDatasetsQuestionForm, DifyDatasetsQuestionQuery>>({
  148. form: {...initFormData},
  149. queryParams: {
  150. pageNum: 1,
  151. pageSize: 10,
  152. question: undefined,
  153. answer: undefined,
  154. sort: undefined,
  155. createUser: undefined,
  156. property: undefined,
  157. params: {}
  158. },
  159. rules: {
  160. id: [
  161. {required: true, message: "主键ID不能为空", trigger: "blur"}
  162. ],
  163. question: [
  164. {required: true, message: "问题不能为空", trigger: "blur"}
  165. ],
  166. answer: [
  167. {required: true, message: "回答不能为空", trigger: "blur"}
  168. ],
  169. sort: [
  170. {required: true, message: "序号不能为空", trigger: "blur"}
  171. ],
  172. createUser: [
  173. {required: true, message: "上传人不能为空", trigger: "blur"}
  174. ],
  175. property: [
  176. {required: true, message: "属性不能为空", trigger: "blur"}
  177. ],
  178. }
  179. });
  180. const {queryParams, form, rules} = toRefs(data);
  181. /** 查询Dify知识问答列表 */
  182. const getList = async () => {
  183. loading.value = true;
  184. const res = await listDifyDatasetsQuestion(queryParams.value);
  185. difyDatasetsQuestionList.value = res.rows;
  186. total.value = res.total;
  187. loading.value = false;
  188. }
  189. /** 取消按钮 */
  190. const cancel = () => {
  191. reset();
  192. dialog.visible = false;
  193. }
  194. /** 表单重置 */
  195. const reset = () => {
  196. form.value = {...initFormData};
  197. difyDatasetsQuestionFormRef.value?.resetFields();
  198. }
  199. /** 搜索按钮操作 */
  200. const handleQuery = () => {
  201. queryParams.value.pageNum = 1;
  202. getList();
  203. }
  204. /** 重置按钮操作 */
  205. const resetQuery = () => {
  206. queryFormRef.value?.resetFields();
  207. handleQuery();
  208. }
  209. /** 多选框选中数据 */
  210. const handleSelectionChange = (selection: DifyDatasetsQuestionVO[]) => {
  211. ids.value = selection.map(item => item.id);
  212. single.value = selection.length != 1;
  213. multiple.value = !selection.length;
  214. }
  215. /** 新增按钮操作 */
  216. const handleAdd = () => {
  217. reset();
  218. dialog.visible = true;
  219. dialog.title = "添加知识条目";
  220. }
  221. /** 修改按钮操作 */
  222. const handleUpdate = async (row?: DifyDatasetsQuestionVO) => {
  223. reset();
  224. const _id = row?.id || ids.value[0]
  225. const res = await getDifyDatasetsQuestion(_id);
  226. Object.assign(form.value, res.data);
  227. dialog.visible = true;
  228. dialog.title = "修改知识条目";
  229. }
  230. /** 提交按钮 */
  231. const submitForm = () => {
  232. difyDatasetsQuestionFormRef.value?.validate(async (valid: boolean) => {
  233. if (valid) {
  234. buttonLoading.value = true;
  235. if (form.value.id) {
  236. await updateDifyDatasetsQuestion(form.value).finally(() => buttonLoading.value = false);
  237. } else {
  238. await addDifyDatasetsQuestion(form.value).finally(() => buttonLoading.value = false);
  239. }
  240. proxy?.$modal.msgSuccess("操作成功");
  241. dialog.visible = false;
  242. await getList();
  243. }
  244. });
  245. }
  246. /** 删除按钮操作 */
  247. const handleDelete = async (row?: DifyDatasetsQuestionVO) => {
  248. const _ids = row?.id || ids.value;
  249. await proxy?.$modal.confirm('是否确认删除知识条目编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
  250. await delDifyDatasetsQuestion(_ids);
  251. proxy?.$modal.msgSuccess("删除成功");
  252. await getList();
  253. }
  254. /** 导出按钮操作 */
  255. const handleExport = () => {
  256. proxy?.download('device/difyDatasetsQuestion/export', {
  257. ...queryParams.value
  258. }, `difyDatasetsQuestion_${new Date().getTime()}.xlsx`)
  259. }
  260. onMounted(() => {
  261. getList();
  262. });
  263. </script>