index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="10">
  4. <!--机构数据-->
  5. <el-col :span="4" :xs="24">
  6. <org-tree v-model="queryParams.orgId" @defaultKey="getDefaultKey" @checkChange="checkChange"
  7. @click="clickTreeNode" wholeTree></org-tree>
  8. </el-col>
  9. <!--用户数据-->
  10. <el-col :span="20" :xs="24">
  11. <div class="main-right-box">
  12. <div class="main-search-box">
  13. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
  14. <el-form-item label="资料名称" prop="title">
  15. <el-input
  16. v-model="queryParams.title"
  17. placeholder="请输入关键字"
  18. clearable
  19. maxlength="50"
  20. @keyup.enter.native="handleQuery"
  21. />
  22. </el-form-item>
  23. <el-form-item label="资料类型" prop="knowledgeId">
  24. <el-select v-model="queryParams.knowledgeId" placeholder="请选择资料类型" style="width: 100%;" clearable>
  25. <el-option v-for="dict in dict.type.edu_materials_type" :key="dict.value" :label="dict.label"
  26. :value="parseInt(dict.value)"></el-option>
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item label="资料状态" prop="isOpen">
  30. <el-select v-model="queryParams.isOpen" placeholder="请选择资料状态" style="width: 100%;" clearable>
  31. <el-option v-for="dict in dict.type.materials_status" :key="dict.value" :label="dict.label"
  32. :value="parseInt(dict.value)"></el-option>
  33. </el-select>
  34. </el-form-item>
  35. <!-- <el-form-item>
  36. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  37. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  38. </el-form-item> -->
  39. </el-form>
  40. <el-row :gutter="10" class="mb8">
  41. <el-col :span="1.5">
  42. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  43. </el-col>
  44. <el-col :span="1.5">
  45. <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button
  49. type="primary"
  50. icon="el-icon-plus"
  51. size="mini"
  52. @click="handleAdd"
  53. v-hasPermi="['core:materials:add']"
  54. >新增资料
  55. </el-button>
  56. </el-col>
  57. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  58. </el-row>
  59. </div>
  60. <!-- 表格数据 -->
  61. <el-table
  62. border
  63. height="646"
  64. size="small"
  65. v-loading="loading" :data="materialsList" @selection-change="handleSelectionChange">
  66. <el-table-column label="序号" type="index" align="center" width="68"/>
  67. <el-table-column label="创建机构" align="left" header-align="center" width="250" prop="orgName"/>
  68. <el-table-column label="资料名称" align="left" header-align="center" width="250" prop="title"/>
  69. <el-table-column label="资料类型" align="center" width="180" prop="knowledgeId">
  70. <template slot-scope="scope">
  71. <dict-tag :options="dict.type.edu_materials_type" :value="parseInt(scope.row.knowledgeId)"/>
  72. </template>
  73. </el-table-column>
  74. <!-- <el-table-column label="资料附件" width="200" align="left" prop="fileNames"/> -->
  75. <!-- <el-table-column label="资料状态" align="center" prop="isOpen">
  76. <template slot-scope="r">{{ r.row.isOpen == 0 ? '待发布' : '已发布' }}</template>
  77. </el-table-column>-->
  78. <el-table-column label="资料状态" width="100" align="center" header-align="center" prop="isOpen">
  79. <template slot-scope="scope">
  80. <dict-tag :options="dict.type.materials_status" :value="scope.row.isOpen"/>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="创建人" align="center" width="150" prop="createBy"/>
  84. <el-table-column label="创建时间" align="center" width="180" prop="createTime"/>
  85. <!-- <el-table-column width="250" scoped-slot="remark" align="center" prop="remark" label="备注"></el-table-column>-->
  86. <el-table-column label="操作" fixed="right" header-align="center" class-name="small-padding fixed-width">
  87. <template slot-scope="scope">
  88. <!-- 公开 按钮显示逻辑: 仅当前用户上传的学习资料且处于未公开状态-->
  89. <el-button
  90. v-if="checkCanEditOpen(scope.row)&&(scope.row.isOpen==0||scope.row.isOpen==2)"
  91. size="mini"
  92. type="text"
  93. icon="el-icon-folder-opened"
  94. @click="handleOpen(scope.row,1)"
  95. v-hasPermi="['core:materials:edit']"
  96. >发布
  97. </el-button>
  98. <!-- 取消公开 按钮显示逻辑: 仅当前用户上传的学习资料且处于公开状态-->
  99. <el-button
  100. v-if="checkCanEditOpen(scope.row)&&scope.row.isOpen==1"
  101. size="mini"
  102. type="text"
  103. icon="el-icon-folder"
  104. @click="handleOpen(scope.row,0)"
  105. v-hasPermi="['core:materials:edit']"
  106. >取消发布
  107. </el-button>
  108. <!-- 编辑与删除按钮显示逻辑: 仅当前用户上传的学习资料且处于未公开状态-->
  109. <el-button
  110. v-if="checkCanEdit(scope.row)"
  111. size="mini"
  112. type="text"
  113. icon="el-icon-edit-outline"
  114. @click="handleUpdate(scope.row)"
  115. v-hasPermi="['core:materials:edit']"
  116. >编辑
  117. </el-button>
  118. <!-- <el-button
  119. v-if="checkCanShowInfo(scope.row)"
  120. size="mini"
  121. type="text"
  122. icon="el-icon-info"
  123. @click="handleInfo(scope.row)"
  124. v-hasPermi="['core:materials:edit']"
  125. >详情
  126. </el-button>-->
  127. <el-button
  128. v-if="checkCanDel(scope.row)"
  129. size="mini"
  130. type="text"
  131. icon="el-icon-delete"
  132. @click="handleDelete(scope.row)"
  133. v-hasPermi="['core:materials:remove']"
  134. >删除
  135. </el-button>
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <pagination
  140. v-show="total>0"
  141. :total="total"
  142. :page.sync="queryParams.pageNum"
  143. :limit.sync="queryParams.pageSize"
  144. @pagination="getList"
  145. />
  146. </div>
  147. </el-col>
  148. </el-row>
  149. <!-- 添加或修改学习资料对话框 -->
  150. <DialogCom :title="title" :visible.sync="open" @close="cancel" width="700px" append-to-body>
  151. <el-form :disabled="title=='知识库详情'" ref="form" :model="form" :rules="rules" label-width="100px">
  152. <el-form-item label="资料名称" prop="title" class="endItem">
  153. <el-input v-model="form.title" placeholder="请输入资料名称" maxlength="50" show-word-limit/>
  154. </el-form-item>
  155. <el-form-item label="资料类型" prop="knowledgeId">
  156. <el-select style="width: 100%" v-model="form.knowledgeId" placeholder="请选择资料类型">
  157. <el-option v-for="dict in dict.type.edu_materials_type" :key="dict.value" :label="dict.label"
  158. :value="dict.value"></el-option>
  159. </el-select>
  160. </el-form-item>
  161. <!-- <el-form-item label="资料内容" prop="content">
  162. <el-input v-model="form.content" placeholder="请输入资料内容" maxlength="200" show-word-limit/>
  163. </el-form-item>-->
  164. <el-form-item label="上传文件" prop="fileList">
  165. <K-file-upload ref="upload" :isShowUploadBtn="title!='知识库详情'"
  166. :defaultValue="formFileListDefualtValue"
  167. v-model="form.fileList"/>
  168. </el-form-item>
  169. <el-form-item prop="remark" label="备注">
  170. <k-textarea v-model="form.remark" placeholder="请输入备注" :length="200"/>
  171. </el-form-item>
  172. </el-form>
  173. <div slot="footer" class="dialog-footer">
  174. <el-button v-show="title!='知识库详情'" type="primary" @click="submitForm">确 定</el-button>
  175. <el-button @click="cancel">取 消</el-button>
  176. </div>
  177. </DialogCom>
  178. </div>
  179. </template>
  180. <script>
  181. import {
  182. listMaterials,
  183. getMaterials,
  184. delMaterials,
  185. addMaterials,
  186. updateMaterials,
  187. editOpen
  188. } from "@/api/core/edu/materials";
  189. import {deptTreeSelect} from "@/api/system/public";
  190. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  191. import {queryKnowledgeList} from "@/api/core/edu/knowledge";
  192. import OrgTree from "@/components/orgTree/index.vue";
  193. import kOrgTree from "@/components/k-orgTree/index.vue";
  194. import KFileUpload from "@/components/K-FileUpload/index.vue";
  195. import tableList from "@/mixins/tableList";
  196. import KTextarea from "@/components/common/textarea.vue";
  197. export default {
  198. name: "Materials",
  199. components: {OrgTree, kOrgTree, KFileUpload, KTextarea},
  200. mixins: [tableList],
  201. dicts: ["edu_materials_type", 'materials_status'],
  202. data() {
  203. return {
  204. // 遮罩层
  205. loading: true,
  206. // 选中数组
  207. ids: [],
  208. // 非单个禁用
  209. single: true,
  210. // 非多个禁用
  211. multiple: true,
  212. // 显示搜索条件
  213. showSearch: true,
  214. // 总条数
  215. total: 0,
  216. // 学习资料表格数据
  217. materialsList: [],
  218. // 弹出层标题
  219. title: "",
  220. // 是否显示弹出层
  221. open: false,
  222. // 机构树选项
  223. deptOptions: undefined,
  224. // 机构名称
  225. deptName: undefined,
  226. //是否关联下级
  227. checked: false,
  228. defaultProps: {
  229. children: "children",
  230. label: "name"
  231. },
  232. formFileListDefualtValue: [],
  233. // 查询参数
  234. queryParams: {
  235. checkSub: true,
  236. pageNum: 1,
  237. pageSize: 10,
  238. title: null,
  239. knowledgeId: null,
  240. content: null,
  241. orgId: null,
  242. isOpen: null,
  243. },
  244. // 表单参数
  245. form: {},
  246. // 表单校验
  247. rules: {
  248. title: [
  249. {required: true, message: "资料名称不能为空", trigger: "blur"}
  250. ],
  251. knowledgeId: [
  252. {required: true, message: "资料类型不能为空", trigger: "blur"}
  253. ],
  254. content: [
  255. {required: true, message: "资料内容不能为空", trigger: "blur"}
  256. ],
  257. fileList: [
  258. {required: true, message: "资料附件不能为空", trigger: "blur"}
  259. ],
  260. },
  261. //默认选中节点
  262. defaultKeys: [],
  263. knowledgeList: [],
  264. openOption: [{
  265. label: "待发布",
  266. value: 0
  267. }, {
  268. label: "已发布",
  269. value: 1
  270. }],
  271. };
  272. },
  273. watch: {
  274. // 根据名称筛选机构树
  275. deptName(val) {
  276. this.$refs.tree.filter(val);
  277. }
  278. },
  279. created() {
  280. this.getDeptTree();
  281. this.getConfigKey("sys.user.initPassword").then(response => {
  282. this.initPassword = response.msg;
  283. });
  284. this.initKnowledgeList();
  285. },
  286. methods: {
  287. /** 查询学习资料列表 */
  288. getList() {
  289. this.loading = true;
  290. listMaterials(this.queryParams).then(response => {
  291. this.materialsList = response.rows;
  292. this.total = response.total;
  293. this.loading = false;
  294. });
  295. },
  296. getDeptTree() {
  297. deptTreeSelect().then(response => {
  298. this.deptOptions = response.data;
  299. });
  300. },
  301. checkCanEdit(row) {
  302. if (row.isOpen == 0 || row.isOpen == 2) {
  303. return true;
  304. }
  305. return false;
  306. },
  307. checkCanDel(row) {
  308. if (row.isOpen == 0 || row.isOpen == 2) {
  309. return true;
  310. }
  311. return false;
  312. },
  313. checkCanShowInfo(row) {
  314. return row.isOpen == 2;
  315. },
  316. checkCanEditOpen(row) {
  317. return row.createId == this.$store.getters.userId;
  318. },
  319. // 节点单击事件
  320. clickTreeNode(data) {
  321. this.queryParams.orgId = data.id;
  322. this.handleQuery();
  323. },
  324. /** 下穿状态改变*/
  325. changeCheckBox() {
  326. this.getList();
  327. },
  328. // 取消按钮
  329. cancel() {
  330. this.open = false;
  331. this.reset();
  332. this.$refs["upload"].clearFiles();
  333. // this.$refs["upload"].fileList = [];
  334. // this.$refs["upload"].fileValueList = [];
  335. },
  336. // 表单重置
  337. reset() {
  338. this.form = {
  339. id: null,
  340. title: null,
  341. knowledgeId: null,
  342. content: null,
  343. orgId: this.$store.getters.orgId,
  344. isOpen: null,
  345. remark: null,
  346. fileNames: null,
  347. fileList: [],
  348. };
  349. // this.formFileListDefualtValue=[];
  350. this.resetForm("form");
  351. this.initKnowledgeList();
  352. },
  353. getDefaultKey(key) {
  354. this.queryParams.orgId = key;
  355. this.getList();
  356. },
  357. //单选框状态改变
  358. checkChange(state) {
  359. this.queryParams.checkSub = state;
  360. this.handleQuery();
  361. },
  362. initKnowledgeList() {
  363. queryKnowledgeList().then(response => {
  364. this.knowledgeList = response;
  365. })
  366. },
  367. // 筛选节点
  368. filterNode(value, data) {
  369. if (!value) return true;
  370. return data.name.indexOf(value) !== -1;
  371. },
  372. // 节点单击事件
  373. handleNodeClick(data) {
  374. this.queryParams.orgId = data.id;
  375. this.handleQuery();
  376. },
  377. /** 搜索按钮操作 */
  378. handleQuery() {
  379. this.queryParams.pageNum = 1;
  380. this.getList();
  381. },
  382. /** 重置按钮操作 */
  383. resetQuery() {
  384. this.resetForm("queryForm");
  385. this.handleQuery();
  386. },
  387. // 多选框选中数据
  388. handleSelectionChange(selection) {
  389. this.ids = selection.map(item => item.id)
  390. this.single = selection.length !== 1
  391. this.multiple = !selection.length
  392. },
  393. /** 删除按钮操作 */
  394. handleDelete(row) {
  395. const ids = row.id || this.ids;
  396. this.$modal.confirm('是否确认删除?').then(function () {
  397. return delMaterials(ids);
  398. }).then(() => {
  399. this.getList();
  400. this.$modal.msgSuccess("删除成功");
  401. }).catch(() => {
  402. });
  403. },
  404. handleOpen(row, isOpen) {
  405. const str = 1 === isOpen ? "发布" : "取消发布";
  406. this.$confirm(`确认要${str}吗?`, "提示", {
  407. confirmButtonText: "确定",
  408. cancelButtonText: "取消",
  409. type: "warning"
  410. })
  411. .then(() => {
  412. editOpen(row.id, isOpen)
  413. .then(response => {
  414. this.$message.success("操作成功");
  415. this.getList();
  416. })
  417. .catch(error => {
  418. this.$message.error("操作失败");
  419. });
  420. })
  421. .catch(() => {
  422. // 用户取消操作
  423. });
  424. },
  425. /** 新增按钮操作 */
  426. handleAdd() {
  427. this.reset();
  428. this.open = true;
  429. this.title = "新增资料文件";
  430. },
  431. /** 修改按钮操作 */
  432. handleUpdate(row) {
  433. this.reset();
  434. const id = row.id || this.ids
  435. getMaterials(id).then(response => {
  436. this.form = response.data;
  437. this.formFileListDefualtValue = this.form.fileList;
  438. this.open = true;
  439. this.title = "修改资料文件";
  440. });
  441. },
  442. /** 详情按钮操作 */
  443. handleInfo(row) {
  444. this.reset();
  445. const id = row.id || this.ids
  446. getMaterials(id).then(response => {
  447. this.form = response.data;
  448. this.formFileListDefualtValue = this.form.fileList;
  449. this.open = true;
  450. this.title = "知识库详情";
  451. });
  452. },
  453. /** 提交按钮 */
  454. submitForm() {
  455. this.$refs["form"].validate(valid => {
  456. if (valid) {
  457. if (this.form.id != null) {
  458. updateMaterials(this.form).then(response => {
  459. this.$modal.msgSuccess("修改成功");
  460. this.open = false;
  461. this.getList();
  462. });
  463. } else {
  464. addMaterials(this.form).then(response => {
  465. this.$modal.msgSuccess("新增成功");
  466. this.open = false;
  467. this.getList();
  468. });
  469. }
  470. }
  471. });
  472. },
  473. listToString(list, separator) {
  474. let strs = "";
  475. separator = separator || ",";
  476. for (let i in list) {
  477. strs += list[i].url + separator;
  478. }
  479. return strs != '' ? strs.substring(0, strs.length - 1) : '';
  480. },
  481. /** 导出按钮操作 */
  482. handleExport() {
  483. this.download('core/materials/export', {
  484. ...this.queryParams
  485. }, `materials_${new Date().getTime()}.xlsx`)
  486. }
  487. }
  488. };
  489. </script>
  490. <style lang="scss">
  491. .ellipsis {
  492. white-space: nowrap;
  493. overflow: hidden;
  494. text-overflow: ellipsis;
  495. }
  496. .endItem .el-input__inner {
  497. padding-right: 50px;
  498. }
  499. </style>