index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--目录数据-->
  5. <el-col :span="4" :xs="24">
  6. <div class="head-container">
  7. <el-tree :data="dirList" :props="defaultProps" :expand-on-click-node="false" ref="tree" node-key="id"
  8. default-expand-all highlight-current @node-click="handleNodeClick" />
  9. </div>
  10. </el-col>
  11. <!--文件数据-->
  12. <el-col :span="16" :xs=24>
  13. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
  14. label-width="68px">
  15. <el-form-item label="文件名称" prop="docName">
  16. <el-input v-model="queryParams.docName" placeholder="请输入文件名称" clearable @keyup.enter.native="handleQuery" />
  17. </el-form-item>
  18. <el-form-item label="文件级别" prop="docLevel">
  19. <el-select v-model="queryParams.docLevel" placeholder="请选择文件级别" @change="handleQuery">
  20. <el-option v-for="item in levelOptions" :key="item.levelId" :label="item.levelName"
  21. :value="item.levelId"></el-option>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="文件年份" prop="createYear">
  25. <el-input v-model="queryParams.createYear" placeholder="请输入文件创建年份" clearable
  26. @keyup.enter.native="handleQuery" />
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  30. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  31. </el-form-item>
  32. </el-form>
  33. <el-row :gutter="10" class="mb8">
  34. <el-col :span="1.5">
  35. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  36. v-hasPermi="['doc:info:add']">上传</el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
  40. v-hasPermi="['doc:info:edit']">修改</el-button>
  41. </el-col>
  42. <el-col :span="1.5">
  43. <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
  44. v-hasPermi="['doc:info:remove']">删除</el-button>
  45. </el-col>
  46. <el-col :span="1.5">
  47. <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
  48. v-hasPermi="['doc:info:export']">导出</el-button>
  49. </el-col>
  50. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  51. </el-row>
  52. <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
  53. <el-table-column type="selection" width="55" align="center" />
  54. <el-table-column label="文件名称" align="center" prop="docName" />
  55. <el-table-column label="文件大小" align="center" prop="docSize" :formatter="fileSizeData" />
  56. <el-table-column label="修改时间" align="center" prop="updateTime" />
  57. <el-table-column label="文件级别" align="center" prop="docLevel" :formatter="fileLevelData" />
  58. <el-table-column label="文件年份" align="center" prop="createYear" />
  59. <el-table-column label="标签" align="center" prop="tagName" />
  60. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  61. <template slot-scope="scope">
  62. <el-button size="mini" type="text" icon="el-icon-view" @click="handleShare(scope.row)"
  63. v-if="checkLevel(scope.row,'share')">分享</el-button>
  64. <el-button size="mini" type="text" icon="el-icon-download" @click="handleDownload(scope.row)"
  65. v-if="checkLevel(scope.row,'download')">下载</el-button>
  66. <el-button size="mini" type="text" icon="el-icon-view" @click="handlePreview(scope.row)">预览</el-button>
  67. <el-button size="mini" type="text" icon="el-icon-view" @click="handleEdit(scope.row)">在线编辑</el-button>
  68. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  69. v-hasPermi="['doc:info:edit']">修改</el-button>
  70. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  71. v-hasPermi="['doc:info:remove']">删除</el-button>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  76. @pagination="getList" />
  77. </el-col>
  78. </el-row>
  79. <!-- 添加或修改文件基本信息对话框 -->
  80. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  81. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  82. <el-form-item label="" prop="docPath">
  83. <!-- <el-input v-model="form.docPath" placeholder="请输入文件路径" /> -->
  84. <file-upload v-model="form.docPath" />
  85. </el-form-item>
  86. <el-form-item label="文件目录" prop="dirId">
  87. <treeselect v-model="form.dirId" :options="dirList" :normalizer="normalizer" placeholder="请选择文件目录" />
  88. </el-form-item>
  89. <el-form-item label="文件名称" prop="docName">
  90. <el-input v-model="form.docName" placeholder="请输入文件名称" />
  91. </el-form-item>
  92. <el-form-item label="文件描述">
  93. <el-input v-model="form.docDesc" type="textarea" placeholder="请输入内容" />
  94. </el-form-item>
  95. <el-form-item label="文件级别" prop="docLevel">
  96. <el-select v-model="form.docLevel" placeholder="请选择文件级别">
  97. <el-option v-for="item in levelOptions" :key="item.levelId" :label="item.levelName"
  98. :value="item.levelId"></el-option>
  99. </el-select>
  100. </el-form-item>
  101. <el-form-item label="文件标签" prop="docLevel">
  102. <el-input v-model="form.docTag" type="textarea" placeholder="请输入文件标签,多个标签以空格分隔,每个标签最好不超过四个字!" />
  103. </el-form-item>
  104. </el-form>
  105. <div slot="footer" class="dialog-footer">
  106. <el-button type="primary" @click="submitForm">确 定</el-button>
  107. <el-button @click="cancel">取 消</el-button>
  108. </div>
  109. </el-dialog>
  110. </div>
  111. </template>
  112. <script>
  113. import {
  114. listInfo,
  115. getInfo,
  116. delInfo,
  117. addInfo,
  118. updateInfo
  119. } from "@/api/doc/info";
  120. import {
  121. listDir,
  122. getDir,
  123. delDir,
  124. addDir,
  125. updateDir,
  126. personalList
  127. } from "@/api/doc/dir";
  128. import {
  129. listLevel
  130. } from "@/api/doc/level";
  131. import Treeselect from "@riophae/vue-treeselect";
  132. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  133. export default {
  134. name: "Info",
  135. components: {
  136. Treeselect
  137. },
  138. data() {
  139. return {
  140. // 遮罩层
  141. loading: true,
  142. // 选中数组
  143. ids: [],
  144. // 非单个禁用
  145. single: true,
  146. // 非多个禁用
  147. multiple: true,
  148. // 显示搜索条件
  149. showSearch: true,
  150. // 总条数
  151. total: 0,
  152. // 文件基本信息表格数据
  153. infoList: [],
  154. //目录ID
  155. dirId: undefined,
  156. //目录数据
  157. dirList: undefined,
  158. //文件等级数据
  159. levelOptions: [],
  160. // 弹出层标题
  161. title: "",
  162. // 是否显示弹出层
  163. open: false,
  164. // 查询参数
  165. queryParams: {
  166. pageNum: 1,
  167. pageSize: 10,
  168. docName: null,
  169. docLevel: null,
  170. createYear: null,
  171. },
  172. // 表单参数
  173. form: {},
  174. defaultProps: {
  175. children: "children",
  176. label: "dirName",
  177. id: "dirId"
  178. },
  179. // 表单校验
  180. rules: {
  181. docName: [{
  182. required: true,
  183. message: "文件名称不能为空",
  184. trigger: "blur"
  185. }],
  186. dirId: [{
  187. required: true,
  188. message: "文件目录不能为空",
  189. trigger: "blur"
  190. }],
  191. docLevel: [{
  192. required: true,
  193. message: "文件级别不能为空",
  194. trigger: "blur"
  195. }],
  196. }
  197. }
  198. },
  199. created() {
  200. this.dirTree();
  201. },
  202. watch: {
  203. "form.docPath": function(path, old) {
  204. if (path && path.lastIndexOf("/") > -1) {
  205. let name = path.slice(path.lastIndexOf("/") + 1);
  206. this.form.docName = name.split("_")[0];
  207. }
  208. }
  209. },
  210. methods: {
  211. /** 转换目录信息数据结构 */
  212. normalizer(node) {
  213. if (node.children && !node.children.length) {
  214. delete node.children;
  215. }
  216. return {
  217. id: node.dirId,
  218. label: node.dirName,
  219. children: node.children
  220. };
  221. },
  222. // 节点单击事件
  223. handleNodeClick(data) {
  224. this.dirId = data.dirId;
  225. this.queryParams.dirId = this.dirId;
  226. this.queryParams.searchValue = this.spaceId;
  227. this.handleQuery();
  228. },
  229. //分享
  230. handleShare(row) {
  231. this.$router.push("/doc/share-user/user/" + row.docId);
  232. },
  233. /**下载按钮操作*/
  234. handleDownload(row) {
  235. location.href = row.docPath;
  236. },
  237. //预览
  238. handlePreview(row) {
  239. row.isEdit = false;
  240. this.$tab.openPage("文件[" + row.docName + "]预览", '/doc/oo-edit/index/' + row.docId, row);
  241. },
  242. //在线编辑
  243. handleEdit(row) {
  244. row.isEdit = true;
  245. this.$tab.openPage("文件[" + row.docName + "]在线编辑", '/doc/oo-edit/index/' + row.docId, row);
  246. },
  247. //先获取左边目录树,拿到目录ID和spaceId才能查询
  248. dirTree() {
  249. this.loading = true;
  250. personalList().then(response => {
  251. this.dirId = response.data[0].dirId;
  252. this.spaceId = response.data[0].spaceId;
  253. this.dirList = this.handleTree(response.data, "dirId");
  254. this.queryParams.dirId = this.dirId;
  255. this.queryParams.searchValue = this.spaceId;
  256. this.getList();
  257. //获取文件级别数据
  258. listLevel().then(response => {
  259. this.levelOptions = response.rows;
  260. });
  261. this.loading = false;
  262. });
  263. },
  264. /** 查询文件基本信息列表 */
  265. getList() {
  266. this.loading = true;
  267. listInfo(this.queryParams).then(response => {
  268. this.infoList = response.rows;
  269. this.total = response.total;
  270. this.loading = false;
  271. });
  272. },
  273. // 取消按钮
  274. cancel() {
  275. this.open = false;
  276. this.reset();
  277. },
  278. // 表单重置
  279. reset() {
  280. this.form = {
  281. docId: null,
  282. dirId: this.dirId,
  283. docName: null,
  284. docType: null,
  285. docSize: null,
  286. classifyId: null,
  287. docDesc: null,
  288. docPath: null,
  289. docLevel: null,
  290. allowEdit: null,
  291. docOf: null,
  292. owner: null,
  293. createYear: null,
  294. createBy: null,
  295. createTime: null,
  296. updateBy: null,
  297. updateTime: null,
  298. remark: null,
  299. isDel: null,
  300. searchValue: this.spaceId
  301. };
  302. this.resetForm("form");
  303. },
  304. /** 搜索按钮操作 */
  305. handleQuery() {
  306. // const para = {
  307. // tagId: 123
  308. // }
  309. // this.queryParams.params = para;
  310. this.queryParams.pageNum = 1;
  311. this.getList();
  312. },
  313. /** 重置按钮操作 */
  314. resetQuery() {
  315. this.resetForm("queryForm");
  316. this.queryParams.dirId = this.dirId;
  317. this.queryParams.searchValue = this.spaceId;
  318. this.handleQuery();
  319. },
  320. // 多选框选中数据
  321. handleSelectionChange(selection) {
  322. this.ids = selection.map(item => item.docId)
  323. this.single = selection.length !== 1
  324. this.multiple = !selection.length
  325. },
  326. /** 新增按钮操作 */
  327. handleAdd() {
  328. this.reset();
  329. this.open = true;
  330. this.title = "添加文件基本信息";
  331. },
  332. /** 修改按钮操作 */
  333. handleUpdate(row) {
  334. this.reset();
  335. const docId = row.docId || this.ids
  336. getInfo(docId, row.createYear).then(response => {
  337. this.form = response.data;
  338. this.open = true;
  339. this.title = "修改文件基本信息";
  340. });
  341. },
  342. /** 提交按钮 */
  343. submitForm() {
  344. this.$refs["form"].validate(valid => {
  345. if (valid) {
  346. if (this.form.docId != null) {
  347. updateInfo(this.form).then(response => {
  348. this.$modal.msgSuccess("修改成功");
  349. this.open = false;
  350. this.getList();
  351. });
  352. } else {
  353. addInfo(this.form).then(response => {
  354. this.$modal.msgSuccess("新增成功");
  355. this.open = false;
  356. this.getList();
  357. });
  358. }
  359. }
  360. });
  361. },
  362. /** 删除按钮操作 */
  363. handleDelete(row) {
  364. const docIds = row.docId || this.ids;
  365. this.$modal.confirm('是否确认删除文件基本信息编号为"' + docIds + '"的数据项?').then(function() {
  366. return delInfo(docIds);
  367. }).then(() => {
  368. this.getList();
  369. this.$modal.msgSuccess("删除成功");
  370. }).catch(() => {});
  371. },
  372. /** 导出按钮操作 */
  373. handleExport() {
  374. this.download('doc/info/export', {
  375. ...this.queryParams
  376. }, `info_${new Date().getTime()}.xlsx`)
  377. },
  378. /**格式化文件大小数据*/
  379. fileSizeData(row, col, value) {
  380. const KB = 1;
  381. const MB = KB * 1024;
  382. const GB = MB * 1024;
  383. if (value < MB) {
  384. return `${(value / KB).toFixed(2)} KB`;
  385. } else if (value < GB) {
  386. return `${(value / MB).toFixed(2)} MB`;
  387. } else {
  388. return `${(value / GB).toFixed(2)} GB`;
  389. }
  390. },
  391. /**处理文档级别数据*/
  392. fileLevelData(row, col, value) {
  393. try {
  394. const obj = this.levelOptions.find(level => level.levelId == row.docLevel);
  395. return obj.levelName;
  396. } catch (e) {}
  397. },
  398. /**根据文件级别,设置是否显示*/
  399. checkLevel(row, role) {
  400. try {
  401. const obj = this.levelOptions.find(level => level.levelId == row.docLevel);
  402. if (obj.levelRole.indexOf(role) != -1) {
  403. return true;
  404. } else {
  405. return false;
  406. }
  407. } catch (e) {}
  408. }
  409. }
  410. };
  411. </script>