index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <!-- -->
  2. <template>
  3. <div class="m-container">
  4. <h2>
  5. <div class="squrt"></div>
  6. 功能字典
  7. </h2>
  8. <div class="m-core">
  9. <save-form
  10. :inline="true"
  11. :model="searchForm"
  12. @submit="search"
  13. @reset="onReSet"
  14. >
  15. <el-form-item>
  16. <el-input
  17. v-model.trim="searchForm.search"
  18. clearable
  19. @keyup.enter.native="search"
  20. placeholder="请输入功能名称"
  21. ></el-input>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button native-type="submit" type="primary">搜索</el-button>
  25. <!-- <el-button native-type="reset" type="danger">重置</el-button> -->
  26. </el-form-item>
  27. </save-form>
  28. <div class="btnList">
  29. <el-button
  30. type="primary"
  31. v-permission="'memberPrivilegesItem/add'"
  32. @click="createDiction()"
  33. >添加按钮</el-button
  34. >
  35. </div>
  36. <div class="tableWrap">
  37. <el-table
  38. :data="tableList"
  39. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  40. style="width: 100%; margin-bottom: 20px; margin-top: 40px"
  41. row-key="id"
  42. border
  43. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  44. >
  45. <el-table-column width="300px" prop="name" label="功能名称">
  46. </el-table-column>
  47. <el-table-column prop="id" width="100px" label="功能ID">
  48. </el-table-column>
  49. <el-table-column prop="code" width="200px" label="功能标识">
  50. </el-table-column>
  51. <el-table-column prop="desc" label="功能描述"> </el-table-column>
  52. <el-table-column label="操作" width="200px">
  53. <template slot-scope="scope">
  54. <el-button
  55. @click="resetDiction(scope.row)"
  56. v-permission="'memberPrivilegesItem/update'"
  57. type="text"
  58. >修改</el-button
  59. >
  60. <el-button
  61. @click="onDelete(scope.row)"
  62. v-permission="'memberPrivilegesItem/del'"
  63. type="text"
  64. >删除</el-button
  65. >
  66. </template>
  67. </el-table-column>
  68. </el-table>
  69. </div>
  70. </div>
  71. <el-dialog
  72. :title="title"
  73. :close-on-click-modal="false"
  74. :visible.sync="branchStatus"
  75. default-expand-all
  76. @close="onFormClose('ruleForm')"
  77. width="500px"
  78. >
  79. <el-form :model="form" :rules="rules" ref="ruleForm">
  80. <el-form-item
  81. label="功能名称"
  82. prop="name"
  83. :label-width="formLabelWidth"
  84. >
  85. <el-input v-model.trim="form.name" autocomplete="off"></el-input>
  86. </el-form-item>
  87. <el-form-item
  88. label="功能标识"
  89. prop="code"
  90. :label-width="formLabelWidth"
  91. >
  92. <el-input v-model.trim="form.code" autocomplete="off"></el-input>
  93. </el-form-item>
  94. <el-form-item
  95. label="父元素ID"
  96. prop="parentId"
  97. :label-width="formLabelWidth"
  98. >
  99. <el-cascader
  100. v-model="form.parentId"
  101. style="width: 100%"
  102. :options="cascaderList"
  103. :props="optionProps"
  104. ></el-cascader>
  105. </el-form-item>
  106. <el-form-item
  107. label="功能描述"
  108. :label-width="formLabelWidth"
  109. prop="desc"
  110. >
  111. <el-input
  112. type="textarea"
  113. v-model.trim="form.desc"
  114. autocomplete="off"
  115. :rows="3"
  116. ></el-input>
  117. </el-form-item>
  118. </el-form>
  119. <span slot="footer" class="dialog-footer">
  120. <el-button @click="branchStatus = false">取 消</el-button>
  121. <el-button @click="onBranchSubmit" type="primary">确 定</el-button>
  122. </span>
  123. </el-dialog>
  124. </div>
  125. </template>
  126. <script>
  127. import axios from "axios";
  128. import { getToken } from "@/utils/auth";
  129. import load from "@/utils/loading";
  130. import { getMemberPrivilegesItem, addMemberPrivilegesItem,resetMemberPrivilegesItem } from "./api";
  131. export default {
  132. data() {
  133. return {
  134. searchForm: {
  135. search: null,
  136. },
  137. branchStatus: false,
  138. tableList: [],
  139. optionProps: {
  140. value: "id",
  141. label: "name",
  142. children: "children",
  143. checkStrictly: true,
  144. },
  145. cascaderList: [], // 父级元素
  146. form: {
  147. id: null,
  148. name: null,
  149. parentId: null,
  150. code: null,
  151. desc: null,
  152. },
  153. formLabelWidth: "100px",
  154. title: "",
  155. rules: {
  156. name: [{ required: true, message: "请输入功能", trigger: "blur" }],
  157. desc: [{ required: true, message: "请输入功能描述", trigger: "blur" }],
  158. code: [{ required: true, message: "请输入功能标识", trigger: "blur" }],
  159. parentId: [
  160. { required: true, message: "请输入父元素ID", trigger: "blur" },
  161. ],
  162. },
  163. disctionStatus: "create",
  164. };
  165. },
  166. //生命周期 - 创建完成(可以访问当前this实例)
  167. created() {},
  168. //生命周期 - 挂载完成(可以访问DOM元素)
  169. mounted() {
  170. // 获取分部
  171. this.init();
  172. },
  173. methods: {
  174. init() {
  175. this.getList();
  176. },
  177. async getList() {
  178. try {
  179. const res = await getMemberPrivilegesItem();
  180. this.tableList = this.setTableData(res.data);
  181. this.cascaderList = this.setTableData(res.data);
  182. this.cascaderList.unshift({
  183. id: 0,
  184. name: "根结点",
  185. children: [],
  186. });
  187. } catch (e) {
  188. console.log(e);
  189. }
  190. },
  191. search() {
  192. // this.rules.page = 1;
  193. // this.getList();
  194. },
  195. onReSet() {},
  196. createDiction() {
  197. this.title = "添加字典";
  198. this.branchStatus = true;
  199. this.disctionStatus = "create";
  200. },
  201. resetDiction(row) {
  202. this.title = "修改字典";
  203. this.disctionStatus = "update";
  204. this.form = {
  205. id: row.id,
  206. name: row.name,
  207. parentId: row.parentId,
  208. code: row.code,
  209. desc: row.desc,
  210. };
  211. this.branchStatus = true;
  212. },
  213. onDelete(row) {},
  214. onBranchSubmit() {
  215. this.$refs["ruleForm"].validate(async (valid) => {
  216. if (valid) {
  217. let form = this.form;
  218. if (this.disctionStatus == "create") {
  219. try {
  220. const res = await addMemberPrivilegesItem({
  221. name: form.name,
  222. parentId: form.parentId.pop(),
  223. code: form.code,
  224. desc: form.desc,
  225. });
  226. this.$message.success("添加成功");
  227. this.getList();
  228. this.branchStatus = false;
  229. } catch (e) {
  230. console.log(e);
  231. }
  232. } else if (this.disctionStatus == "update") {
  233. if (typeof form.parentId === "object") {
  234. form.parentId = form.parentId.pop();
  235. }
  236. try{
  237. const res = await resetMemberPrivilegesItem(form)
  238. this.$message.success("修改成功");
  239. this.getList();
  240. this.branchStatus = false;
  241. }catch(e){
  242. console.log(e)
  243. }
  244. }
  245. } else {
  246. return false;
  247. }
  248. });
  249. },
  250. setTableData(result) {
  251. let list = [];
  252. list = result.map((res) => {
  253. let tempList = {};
  254. tempList = {
  255. id: res.id,
  256. name: res.name,
  257. parentId: res.parentId,
  258. code: res.code,
  259. desc: res.desc,
  260. };
  261. if (res.memberPrivilegesItems && res.memberPrivilegesItems.length > 0) {
  262. tempList.children = this.setTableData(res.memberPrivilegesItems);
  263. }
  264. return tempList;
  265. });
  266. return list;
  267. },
  268. onFormClose(formName) {
  269. // 关闭弹窗重置验证
  270. this.form = {
  271. id: null,
  272. name: null,
  273. parentId: null,
  274. code: null,
  275. desc: null,
  276. };
  277. this.$refs[formName].resetFields();
  278. },
  279. },
  280. };
  281. </script>
  282. <style lang='scss' scoped>
  283. .btnList {
  284. margin-bottom: 20px;
  285. }
  286. </style>