index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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="handlePreview(scope.row)">分享</el-button>
  61. <el-button size="mini" type="text" icon="el-icon-view" @click="handlePreview(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. handlePreview(row) {
  222. row.isEdit = false;
  223. this.$tab.openPage("文件[" + row.docName + "]预览", '/doc/oo-edit/index/' + row.docId, row);
  224. },
  225. //在线编辑
  226. handleEdit(row) {
  227. row.isEdit = true;
  228. this.$tab.openPage("文件[" + row.docName + "]在线编辑", '/doc/oo-edit/index/' + row.docId, row);
  229. },
  230. //先获取左边目录树,拿到目录ID和spaceId才能查询
  231. dirTree() {
  232. this.loading = true;
  233. personalList().then(response => {
  234. this.dirId = response.data[0].dirId;
  235. this.spaceId = response.data[0].spaceId;
  236. this.dirList = this.handleTree(response.data, "dirId");
  237. this.queryParams.dirId = this.dirId;
  238. this.queryParams.searchValue = this.spaceId;
  239. this.getList();
  240. this.loading = false;
  241. });
  242. },
  243. /** 查询文件基本信息列表 */
  244. getList() {
  245. this.loading = true;
  246. listInfo(this.queryParams).then(response => {
  247. this.infoList = response.rows;
  248. this.total = response.total;
  249. this.loading = false;
  250. });
  251. },
  252. // 取消按钮
  253. cancel() {
  254. this.open = false;
  255. this.reset();
  256. },
  257. // 表单重置
  258. reset() {
  259. this.form = {
  260. docId: null,
  261. dirId: this.dirId,
  262. docName: null,
  263. docType: null,
  264. docSize: null,
  265. classifyId: null,
  266. docDesc: null,
  267. docPath: null,
  268. docLevel: null,
  269. allowEdit: null,
  270. docOf: null,
  271. owner: null,
  272. createYear: null,
  273. createBy: null,
  274. createTime: null,
  275. updateBy: null,
  276. updateTime: null,
  277. remark: null,
  278. isDel: null,
  279. searchValue: this.spaceId
  280. };
  281. this.resetForm("form");
  282. },
  283. /** 搜索按钮操作 */
  284. handleQuery() {
  285. this.queryParams.pageNum = 1;
  286. this.getList();
  287. },
  288. /** 重置按钮操作 */
  289. resetQuery() {
  290. this.resetForm("queryForm");
  291. this.queryParams.dirId = this.dirId;
  292. this.queryParams.searchValue = this.spaceId;
  293. this.handleQuery();
  294. },
  295. // 多选框选中数据
  296. handleSelectionChange(selection) {
  297. this.ids = selection.map(item => item.docId)
  298. this.single = selection.length !== 1
  299. this.multiple = !selection.length
  300. },
  301. /** 新增按钮操作 */
  302. handleAdd() {
  303. this.reset();
  304. listLevel().then(response => {
  305. this.levelOptions = response.rows;
  306. this.open = true;
  307. this.title = "添加文件基本信息";
  308. });
  309. },
  310. /** 修改按钮操作 */
  311. handleUpdate(row) {
  312. this.reset();
  313. const docId = row.docId || this.ids
  314. getInfo(docId, row.createYear).then(response => {
  315. this.form = response.data;
  316. this.open = true;
  317. this.title = "修改文件基本信息";
  318. });
  319. },
  320. /** 提交按钮 */
  321. submitForm() {
  322. this.$refs["form"].validate(valid => {
  323. if (valid) {
  324. if (this.form.docId != null) {
  325. updateInfo(this.form).then(response => {
  326. this.$modal.msgSuccess("修改成功");
  327. this.open = false;
  328. this.getList();
  329. });
  330. } else {
  331. addInfo(this.form).then(response => {
  332. this.$modal.msgSuccess("新增成功");
  333. this.open = false;
  334. this.getList();
  335. });
  336. }
  337. }
  338. });
  339. },
  340. /** 删除按钮操作 */
  341. handleDelete(row) {
  342. const docIds = row.docId || this.ids;
  343. this.$modal.confirm('是否确认删除文件基本信息编号为"' + docIds + '"的数据项?').then(function() {
  344. return delInfo(docIds);
  345. }).then(() => {
  346. this.getList();
  347. this.$modal.msgSuccess("删除成功");
  348. }).catch(() => {});
  349. },
  350. /** 导出按钮操作 */
  351. handleExport() {
  352. this.download('doc/info/export', {
  353. ...this.queryParams
  354. }, `info_${new Date().getTime()}.xlsx`)
  355. },
  356. /**格式化文件大小数据*/
  357. fileSizeData(row, col, value) {
  358. const KB = 1;
  359. const MB = KB * 1024;
  360. const GB = MB * 1024;
  361. if (value < MB) {
  362. return `${(value / KB).toFixed(2)} KB`;
  363. } else if (value < GB) {
  364. return `${(value / MB).toFixed(2)} MB`;
  365. } else {
  366. return `${(value / GB).toFixed(2)} GB`;
  367. }
  368. }
  369. }
  370. };
  371. </script>