publicSpace.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="10" class="mb8">
  4. <el-col :span="1.5">
  5. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  6. v-hasPermi="['doc:dir:add']">新增</el-button>
  7. </el-col>
  8. <el-col :span="1.5">
  9. <el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">展开/折叠</el-button>
  10. </el-col>
  11. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  12. </el-row>
  13. <el-table v-if="refreshTable" v-loading="loading" :data="dirList" row-key="dirId" :default-expand-all="isExpandAll"
  14. :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
  15. <el-table-column label="目录名称" align="left" prop="dirName" />
  16. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  17. <template slot-scope="scope">
  18. <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)"
  19. v-hasPermi="['doc:dir:add']">新增</el-button>
  20. <el-button v-if="scope.row.parentId != 0" size="mini" type="text" icon="el-icon-edit"
  21. @click="handleUpdate(scope.row)" v-hasPermi="['doc:dir:edit']">修改</el-button>
  22. <el-button v-if="scope.row.parentId != 0" size="mini" type="text" icon="el-icon-delete"
  23. @click="handleDelete(scope.row)" v-hasPermi="['doc:dir:remove']">删除</el-button>
  24. </template>
  25. </el-table-column>
  26. </el-table>
  27. <!-- 添加或修改目录信息对话框 -->
  28. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  29. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  30. <el-form-item label="上级目录" prop="parentId">
  31. <treeselect v-model="form.parentId" :options="dirOptions" :normalizer="normalizer" placeholder="请选择上级目录" />
  32. </el-form-item>
  33. <el-form-item label="目录名称" prop="dirName">
  34. <el-input v-model="form.dirName" placeholder="请输入目录名称" />
  35. </el-form-item>
  36. <el-form-item label="备注" prop="remark">
  37. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  38. </el-form-item>
  39. </el-form>
  40. <div slot="footer" class="dialog-footer">
  41. <el-button type="primary" @click="submitForm">确 定</el-button>
  42. <el-button @click="cancel">取 消</el-button>
  43. </div>
  44. </el-dialog>
  45. </div>
  46. </template>
  47. <script>
  48. import {
  49. listDir,
  50. getDir,
  51. delDir,
  52. addDir,
  53. updateDir,
  54. personalList
  55. } from "@/api/doc/dir";
  56. import {
  57. getPersonalSpace
  58. } from "@/api/doc/space";
  59. import {
  60. listExpand,
  61. getExpand,
  62. delExpand,
  63. addExpand,
  64. updateExpand
  65. } from "@/api/doc/expand";
  66. import Treeselect from "@riophae/vue-treeselect";
  67. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  68. export default {
  69. name: "Dir",
  70. components: {
  71. Treeselect
  72. },
  73. data() {
  74. return {
  75. // 遮罩层
  76. loading: true,
  77. // 显示搜索条件
  78. showSearch: true,
  79. // 目录信息表格数据
  80. dirList: [],
  81. // 目录信息树选项
  82. dirOptions: [],
  83. // 弹出层标题
  84. title: "",
  85. // 是否显示弹出层
  86. open: false,
  87. openSpace: false,
  88. // 是否展开,默认全部展开
  89. isExpandAll: true,
  90. // 重新渲染表格状态
  91. refreshTable: true,
  92. // 查询参数
  93. queryParams: {
  94. parentId: null,
  95. dirName: null,
  96. },
  97. //个人空间数据
  98. spaceData: {},
  99. // 表单参数
  100. form: {},
  101. formSpace: {},
  102. // 表单校验
  103. rules: {
  104. dirName: [{
  105. required: true,
  106. message: "目录名称不能为空",
  107. trigger: "blur"
  108. }],
  109. parentId: [{
  110. required: true,
  111. message: "上级目录不能为空",
  112. trigger: "blur"
  113. }],
  114. },
  115. // 表单校验
  116. rulesSpace: {
  117. expandCap: [{
  118. required: true,
  119. message: "扩容容量不能为空",
  120. trigger: "blur"
  121. }],
  122. remark: [{
  123. required: true,
  124. message: "申请理由不能为空",
  125. trigger: "blur"
  126. }],
  127. }
  128. };
  129. },
  130. created() {
  131. this.getList();
  132. this.spaceInfo();
  133. },
  134. methods: {
  135. /** 查询个人空间相关信息 */
  136. spaceInfo() {
  137. this.loading = true;
  138. getPersonalSpace().then(response => {
  139. this.spaceData = response.data;
  140. this.loading = false;
  141. });
  142. },
  143. /** 查询目录信息列表 */
  144. getList() {
  145. this.loading = true;
  146. personalList().then(response => {
  147. this.dirList = this.handleTree(response.data, "dirId");
  148. this.loading = false;
  149. });
  150. },
  151. /** 转换目录信息数据结构 */
  152. normalizer(node) {
  153. if (node.children && !node.children.length) {
  154. delete node.children;
  155. }
  156. return {
  157. id: node.dirId,
  158. label: node.dirName,
  159. children: node.children
  160. };
  161. },
  162. // 取消按钮
  163. cancel() {
  164. this.open = false;
  165. this.reset();
  166. },
  167. // 取消按钮
  168. cancelSpace() {
  169. this.openSpace = false;
  170. this.reset();
  171. },
  172. // 表单重置
  173. reset() {
  174. this.form = {
  175. dirId: null,
  176. spaceId: null,
  177. parentId: null,
  178. dirName: null,
  179. dirPath: null,
  180. createBy: null,
  181. createTime: null,
  182. updateBy: null,
  183. updateTime: null,
  184. remark: null,
  185. isDel: null
  186. };
  187. this.resetForm("form");
  188. },
  189. /** 搜索按钮操作 */
  190. handleQuery() {
  191. this.getList();
  192. },
  193. /** 重置按钮操作 */
  194. resetQuery() {
  195. this.resetForm("queryForm");
  196. this.handleQuery();
  197. },
  198. /** 新增按钮操作 */
  199. handleAdd(row) {
  200. this.reset();
  201. // this.getTreeselect();
  202. if (row != null && row.dirId) {
  203. this.form.parentId = row.dirId;
  204. // } else {
  205. // this.form.parentId = 0;
  206. }
  207. this.open = true;
  208. this.title = "添加目录信息";
  209. personalList().then(response => {
  210. this.form.spaceId = response.data[0].spaceId;
  211. this.dirOptions = this.handleTree(response.data, "dirId");
  212. });
  213. },
  214. /** 展开/折叠操作 */
  215. toggleExpandAll() {
  216. this.refreshTable = false;
  217. this.isExpandAll = !this.isExpandAll;
  218. this.$nextTick(() => {
  219. this.refreshTable = true;
  220. });
  221. },
  222. /** 修改按钮操作 */
  223. handleUpdate(row) {
  224. this.reset();
  225. if (row != null) {
  226. this.form.parentId = row.dirId;
  227. }
  228. getDir(row.dirId).then(response => {
  229. this.form = response.data;
  230. this.open = true;
  231. this.title = "修改目录信息";
  232. });
  233. personalList().then(response => {
  234. this.dirOptions = this.handleTree(response.data, "dirId");
  235. });
  236. },
  237. /** 提交按钮 */
  238. submitForm() {
  239. this.$refs["form"].validate(valid => {
  240. if (valid) {
  241. if (this.form.dirId != null) {
  242. updateDir(this.form).then(response => {
  243. this.$modal.msgSuccess("修改成功");
  244. this.open = false;
  245. this.getList();
  246. });
  247. } else {
  248. addDir(this.form).then(response => {
  249. this.$modal.msgSuccess("新增成功");
  250. this.open = false;
  251. this.getList();
  252. });
  253. }
  254. }
  255. });
  256. },
  257. /** 删除按钮操作 */
  258. handleDelete(row) {
  259. this.$modal.confirm('是否确认删除目录信息编号为"' + row.dirId + '"的数据项?').then(function() {
  260. return delDir(row.dirId);
  261. }).then(() => {
  262. this.getList();
  263. this.$modal.msgSuccess("删除成功");
  264. }).catch(() => {});
  265. }
  266. }
  267. };
  268. </script>