index.vue 14 KB

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