index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索 -->
  4. <el-form inline label-width="100px" size="mini" @submit.native.prevent>
  5. <el-form-item>
  6. <el-button
  7. type="primary"
  8. icon="el-icon-plus"
  9. plain
  10. @click="getChange()"
  11. v-hasPermi="['device:function:add']"
  12. >新增</el-button
  13. >
  14. </el-form-item>
  15. </el-form>
  16. <!-- 表格 -->
  17. <el-table :data="tableData" v-loading="loading">
  18. <el-table-column label="权限ID" prop="id" align="center" />
  19. <el-table-column label="功能名称" prop="name" align="center" />
  20. <el-table-column
  21. label="功能分类"
  22. prop="type"
  23. align="center"
  24. ></el-table-column>
  25. <el-table-column label="状态" align="center">
  26. <template slot-scope="scope">
  27. <dict-tag
  28. :options="dict.type.sys_normal_disable"
  29. :value="scope.row.status"
  30. />
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="操作" align="center">
  34. <template slot-scope="scope">
  35. <el-button
  36. type="text"
  37. @click="getChange(scope.row)"
  38. v-hasPermi="['device:function:edit']"
  39. >
  40. 编辑
  41. </el-button>
  42. <el-button
  43. type="delete"
  44. @click="getDelete(scope.row)"
  45. v-hasPermi="['device:function:delete']"
  46. >
  47. 删除
  48. </el-button>
  49. </template>
  50. </el-table-column>
  51. </el-table>
  52. <!-- 新增弹窗 -->
  53. <el-dialog
  54. :title="title"
  55. :visible.sync="dialogVisible"
  56. width="500px"
  57. :before-close="getCancel"
  58. >
  59. <el-form :model="form" :rules="rules" ref="form" label-width="100px">
  60. <el-form-item label="功能名称:" prop="name">
  61. <el-input v-model="form.name" placeholder="请输入分类名称" />
  62. </el-form-item>
  63. <el-form-item label="功能分类:" prop="type">
  64. <el-input-number v-model="form.type" />
  65. </el-form-item>
  66. <el-form-item label="启用状态:" prop="status">
  67. <el-radio-group v-model="form.status">
  68. <el-radio :label="0">正常</el-radio>
  69. <el-radio :label="1">停用</el-radio>
  70. </el-radio-group>
  71. </el-form-item>
  72. </el-form>
  73. <div slot="footer">
  74. <el-button @click="getCancel">取消</el-button>
  75. <el-button type="primary" @click="getSubmit">确定</el-button>
  76. </div>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script>
  81. import { create, edit, list } from "@/api/device/function";
  82. import { callBack } from "@/utils/DialogUtil";
  83. export default {
  84. dicts: ["sys_normal_disable"],
  85. data() {
  86. return {
  87. // 遮罩层
  88. loading: true,
  89. // 表格数据
  90. tableData: [],
  91. // 弹窗
  92. dialogVisible: false,
  93. title: "",
  94. form: {
  95. name: "",
  96. type: "",
  97. status: 0,
  98. },
  99. rules: {
  100. name: [
  101. {
  102. required: true,
  103. message: "请输入功能名称",
  104. trigger: "blur",
  105. },
  106. ],
  107. type: [
  108. {
  109. required: true,
  110. message: "请选择功能分类",
  111. trigger: "change",
  112. },
  113. ],
  114. status: [
  115. {
  116. required: true,
  117. message: "请选择状态",
  118. trigger: "change",
  119. },
  120. ],
  121. },
  122. };
  123. },
  124. mounted() {
  125. this.getList();
  126. },
  127. methods: {
  128. // 权限列表
  129. getList() {
  130. this.loading = true;
  131. list({ isDelete: 0 }).then((res) => {
  132. if (res.code === 0) {
  133. this.tableData = res.data;
  134. this.loading = false;
  135. }
  136. });
  137. },
  138. // 新增 / 编辑
  139. getChange(row) {
  140. this.dialogVisible = true;
  141. this.form = row
  142. ? row
  143. : {
  144. name: "",
  145. type: "",
  146. status: 0,
  147. };
  148. this.title = row ? "编辑" : "新增";
  149. },
  150. // 取消
  151. getCancel() {
  152. this.$refs.form.clearValidate();
  153. this.dialogVisible = false;
  154. },
  155. // 确定
  156. getSubmit() {
  157. this.$refs.form.validate((valid) => {
  158. if (valid) {
  159. if (this.form.id) {
  160. // 编辑
  161. edit(this.form).then((res) => {
  162. if (res.code === 0) {
  163. this.$message.success("修改成功!");
  164. this.dialogVisible = false;
  165. this.getList();
  166. }
  167. });
  168. } else {
  169. // 新增
  170. create(this.form).then((res) => {
  171. if (res.code === 0) {
  172. this.$message.success("创建成功!");
  173. this.dialogVisible = false;
  174. this.getList();
  175. }
  176. });
  177. }
  178. } else {
  179. return false;
  180. }
  181. });
  182. },
  183. // 删除
  184. getDelete(row) {
  185. var that = this;
  186. callBack(that, function () {
  187. that
  188. .$confirm(`是否删除${row.name}?`, "提示", {
  189. confirmButtonText: "确定",
  190. cancelButtonText: "取消",
  191. type: "warning",
  192. })
  193. .then(() => {
  194. that.form = row;
  195. that.form.isDelete = 1;
  196. edit(that.form).then((res) => {
  197. if (res.code === 0) {
  198. that.$message.success("已删除!");
  199. that.getList();
  200. }
  201. });
  202. });
  203. });
  204. // this.$alert(`删除后数据不可恢复,请谨慎进行该操作!`, "温馨提示", {
  205. // confirmButtonText: "确定",
  206. // }).then(() => {
  207. // setTimeout(() => {
  208. // this.$confirm(`是否删除${row.name}?`, "提示", {
  209. // confirmButtonText: "确定",
  210. // cancelButtonText: "取消",
  211. // type: "warning",
  212. // }).then(() => {
  213. // this.form = row;
  214. // this.form.isDelete = 1;
  215. // edit(this.form).then((res) => {
  216. // if (res.code === 0) {
  217. // this.$message.success("已删除!");
  218. // this.getList();
  219. // }
  220. // });
  221. // });
  222. // }, 300);
  223. // });
  224. },
  225. },
  226. };
  227. </script>