index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="知识库名" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入知识库名"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-row :gutter="10" class="mb8">
  19. <el-col :span="1.5">
  20. <el-button
  21. type="primary"
  22. plain
  23. icon="el-icon-plus"
  24. size="mini"
  25. @click="handleAdd"
  26. v-hasPermi="['fastGpt:fastGptDataset:add']"
  27. >新增</el-button>
  28. </el-col>
  29. <el-col :span="1.5">
  30. <el-button
  31. type="warning"
  32. plain
  33. icon="el-icon-edit"
  34. size="mini"
  35. @click="handleSync"
  36. v-hasPermi="['fastGpt:fastGptDataset:edit']"
  37. >同步知识库信息</el-button>
  38. </el-col>
  39. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  40. </el-row>
  41. <el-table v-loading="loading" :data="fastGptDatasetList" @selection-change="handleSelectionChange">
  42. <el-table-column type="selection" width="55" align="center" />
  43. <el-table-column label="知识库id" align="center" prop="datasetId" />
  44. <el-table-column label="知识库名" align="center" prop="name" />
  45. <el-table-column label="介绍" align="center" prop="intro" />
  46. <el-table-column label="头像地址" align="center" prop="avatar">
  47. <template slot-scope="scope">
  48. <img :src="scope.row.avatar" style="height: 80px">
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="是否私有" align="center" prop="isOwner">
  52. <template slot-scope="scope">
  53. {{ scope.row.isOwner === 0 ? '是' : '否' }}
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="更新时间" align="center" prop="updateTime" width="180"/>
  57. <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
  58. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  59. <template slot-scope="scope">
  60. <el-button
  61. size="mini"
  62. type="text"
  63. icon="el-icon-edit"
  64. @click="handleCollection(scope.row.datasetId)"
  65. >集合管理</el-button>
  66. <el-button
  67. size="mini"
  68. type="text"
  69. icon="el-icon-delete"
  70. @click="handleDelete(scope.row)"
  71. v-hasPermi="['fastGpt:fastGptDataset:remove']"
  72. >删除</el-button>
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. <pagination
  77. v-show="total>0"
  78. :total="total"
  79. :page.sync="queryParams.pageNum"
  80. :limit.sync="queryParams.pageSize"
  81. @pagination="getList"
  82. />
  83. <!-- 添加知识库列对话框 -->
  84. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  85. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  86. <el-form-item label="父级ID" prop="parentid">
  87. <el-input v-model="form.parentid" placeholder="用于构建目录结构。通常可以为 null 或者直接不传。" />
  88. </el-form-item>
  89. <el-form-item label="类型" prop="type">
  90. <el-select v-model="form.type" placeholder="代表普通知识库和文件夹。不传则代表创建普通知识库。">
  91. <el-option
  92. v-for="item in typeOptions"
  93. :key="item.dictValue"
  94. :label="item.dictLabel"
  95. :value="item.dictValue"
  96. />
  97. </el-select>
  98. </el-form-item>
  99. <el-form-item label="知识库名" prop="name">
  100. <el-input v-model="form.name" placeholder="请输入知识库名" />
  101. </el-form-item>
  102. <el-form-item label="介绍" prop="intro">
  103. <el-input type="textarea" :rows="3" v-model="form.intro" placeholder="请输入介绍" />
  104. </el-form-item>
  105. <el-form-item label="知识库头像" prop="avatar">
  106. <ImageUpload v-model="form.avatar" type="image" :limit="1" :width="100" :height="100" disabled/>
  107. </el-form-item>
  108. <el-form-item label="向量模型" prop="vectorModel">
  109. <el-input v-model="form.vectorModel" placeholder="请输入向量模型(建议传空,用系统默认的)" />
  110. </el-form-item>
  111. <el-form-item label="文本处理模型" prop="agentModel">
  112. <el-input v-model="form.agentModel" placeholder="请输入文本处理模型(建议传空,用系统默认的)" />
  113. </el-form-item>
  114. </el-form>
  115. <div slot="footer" class="dialog-footer">
  116. <el-button type="primary" @click="submitForm">确 定</el-button>
  117. <el-button @click="cancel">取 消</el-button>
  118. </div>
  119. </el-dialog>
  120. </div>
  121. </template>
  122. <script>
  123. import ImageUpload from '@/components/ImageUpload'
  124. import { listFastGptDataset, getFastGptDataset, delFastGptDataset, addFastGptDataset, updateFastGptDataset, exportFastGptDataset } from "@/api/fastGpt/fastGptDataset";
  125. import {syncDataset} from "../../../api/fastGpt/fastGptDataset";
  126. export default {
  127. name: "FastGptDataset",
  128. components: {ImageUpload},
  129. data() {
  130. return {
  131. // 遮罩层
  132. loading: true,
  133. // 导出遮罩层
  134. exportLoading: false,
  135. // 选中数组
  136. ids: [],
  137. // 非单个禁用
  138. single: true,
  139. // 非多个禁用
  140. multiple: true,
  141. // 显示搜索条件
  142. showSearch: true,
  143. // 总条数
  144. total: 0,
  145. // 知识库列表格数据
  146. fastGptDatasetList: [],
  147. //知识库类型
  148. typeOptions: [
  149. { dictLabel: "普通知识库", dictValue: 'dataset' },
  150. { dictLabel: "文件夹", dictValue: 'folder' },
  151. ],
  152. // 弹出层标题
  153. title: "",
  154. // 是否显示弹出层
  155. open: false,
  156. // 查询参数
  157. queryParams: {
  158. pageNum: 1,
  159. pageSize: 10,
  160. parentid: null,
  161. type: null,
  162. name: null,
  163. intro: null,
  164. avatar: null,
  165. vectorModel: null,
  166. agentModel: null,
  167. permission: null,
  168. canWrite: null,
  169. isOwner: null,
  170. updateTime: null,
  171. createTime: null,
  172. companyId: null
  173. },
  174. // 表单参数
  175. form: {},
  176. // 表单校验
  177. rules: {
  178. name: [
  179. { required: true, message: "名称不能为空", trigger: "blur" }
  180. ],
  181. }
  182. };
  183. },
  184. created() {
  185. this.getList();
  186. },
  187. methods: {
  188. /** 查询知识库列列表 */
  189. getList() {
  190. this.loading = true;
  191. listFastGptDataset(this.queryParams).then(response => {
  192. this.fastGptDatasetList = response.rows;
  193. this.total = response.total;
  194. this.loading = false;
  195. });
  196. },
  197. // 取消按钮
  198. cancel() {
  199. this.open = false;
  200. this.reset();
  201. },
  202. // 表单重置
  203. reset() {
  204. this.form = {
  205. datasetId: null,
  206. parentid: null,
  207. type: "dataset",
  208. name: null,
  209. intro: null,
  210. avatar: null,
  211. vectorModel: null,
  212. agentModel: null,
  213. permission: null,
  214. canWrite: null,
  215. isOwner: null,
  216. updateTime: null,
  217. createTime: null,
  218. companyId: null
  219. };
  220. this.resetForm("form");
  221. },
  222. /** 搜索按钮操作 */
  223. handleQuery() {
  224. this.queryParams.pageNum = 1;
  225. this.getList();
  226. },
  227. /** 重置按钮操作 */
  228. resetQuery() {
  229. this.resetForm("queryForm");
  230. this.handleQuery();
  231. },
  232. // 多选框选中数据
  233. handleSelectionChange(selection) {
  234. this.ids = selection.map(item => item.datasetId)
  235. this.single = selection.length!==1
  236. this.multiple = !selection.length
  237. },
  238. /** 新增按钮操作 */
  239. handleAdd() {
  240. this.reset();
  241. this.open = true;
  242. this.title = "添加知识库列";
  243. },
  244. handleSync(){
  245. syncDataset().then(res => {
  246. this.msgSuccess("同步成功");
  247. this.getList();
  248. })
  249. },
  250. //跳转到集合管理页面
  251. handleCollection(datasetId){
  252. this.$router.push('/fastGpt/fastGptDataset/Collection/fastGptCollection/'+datasetId)
  253. },
  254. /** 修改按钮操作 */
  255. handleUpdate(row) {
  256. this.reset();
  257. const datasetId = row.datasetId || this.ids
  258. getFastGptDataset(datasetId).then(response => {
  259. this.form = response.data;
  260. this.open = true;
  261. this.title = "修改知识库列";
  262. });
  263. },
  264. /** 提交按钮 */
  265. submitForm() {
  266. this.$refs["form"].validate(valid => {
  267. if (valid) {
  268. if (this.form.datasetId != null) {
  269. updateFastGptDataset(this.form).then(response => {
  270. this.msgSuccess("修改成功");
  271. this.open = false;
  272. this.getList();
  273. });
  274. } else {
  275. addFastGptDataset(this.form).then(response => {
  276. this.msgSuccess("新增成功");
  277. this.open = false;
  278. this.getList();
  279. });
  280. }
  281. }
  282. });
  283. },
  284. /** 删除按钮操作 */
  285. handleDelete(row) {
  286. const datasetIds = row.datasetId || this.ids;
  287. this.$confirm('是否确认删除知识库列编号为"' + datasetIds + '"的数据项?', "警告", {
  288. confirmButtonText: "确定",
  289. cancelButtonText: "取消",
  290. type: "warning"
  291. }).then(function() {
  292. return delFastGptDataset(datasetIds);
  293. }).then((res) => {
  294. this.getList();
  295. if (res.data.length){
  296. this.msgError("部分删除失败:"+res.data);
  297. }else {
  298. this.msgSuccess("删除成功");
  299. }
  300. }).catch(() => {});
  301. },
  302. /** 导出按钮操作 */
  303. handleExport() {
  304. const queryParams = this.queryParams;
  305. this.$confirm('是否确认导出所有知识库列数据项?', "警告", {
  306. confirmButtonText: "确定",
  307. cancelButtonText: "取消",
  308. type: "warning"
  309. }).then(() => {
  310. this.exportLoading = true;
  311. return exportFastGptDataset(queryParams);
  312. }).then(response => {
  313. this.download(response.msg);
  314. this.exportLoading = false;
  315. }).catch(() => {});
  316. }
  317. }
  318. };
  319. </script>