index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="one">
  6. <el-form
  7. :model="queryParams"
  8. ref="queryForm"
  9. v-show="showSearch"
  10. :inline="true"
  11. >
  12. <el-form-item label="角色名称" prop="roleName">
  13. <el-input
  14. v-model="queryParams.roleName"
  15. placeholder="请输入角色名称"
  16. clearable
  17. size="small"
  18. style="width: 240px"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button
  24. type="primary"
  25. icon="el-icon-search"
  26. size="mini"
  27. @click="handleQuery"
  28. >搜索</el-button
  29. >
  30. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  31. >重置</el-button
  32. >
  33. </el-form-item>
  34. </el-form>
  35. </el-col>
  36. <el-col :span="24" class="two">
  37. <el-table
  38. v-loading="loading"
  39. :data="roleList"
  40. border
  41. :header-cell-style="{ 'text-align': 'center' }"
  42. :cell-style="{ 'text-align': 'center' }"
  43. >
  44. <el-table-column
  45. label="角色名称"
  46. prop="roleName"
  47. :show-overflow-tooltip="true"
  48. />
  49. <el-table-column
  50. label="权限字符"
  51. prop="roleKey"
  52. :show-overflow-tooltip="true"
  53. />
  54. <el-table-column
  55. label="操作"
  56. align="center"
  57. class-name="small-padding fixed-width"
  58. >
  59. <template slot-scope="scope">
  60. <el-button
  61. size="mini"
  62. type="text"
  63. icon="el-icon-refresh-right"
  64. @click="toRelation(scope.row)"
  65. v-hasPermi="['system:role:relation']"
  66. >账号等级关联</el-button
  67. >
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <pagination
  72. v-show="total > 0"
  73. :total="total"
  74. :page.sync="queryParams.pageNum"
  75. :limit.sync="queryParams.pageSize"
  76. @pagination="getList"
  77. />
  78. </el-col>
  79. </el-col>
  80. </el-row>
  81. <el-dialog
  82. :title="dialog.title"
  83. :visible.sync="dialog.show"
  84. width="30%"
  85. :before-close="toClose"
  86. >
  87. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  88. <el-form-item label="角色名称">
  89. <el-input v-model="form.roleName" disabled></el-input>
  90. </el-form-item>
  91. <el-form-item label="权限字符">
  92. <el-input v-model="form.roleKey" disabled></el-input>
  93. </el-form-item>
  94. <el-form-item label="账号等级" prop="level">
  95. <el-radio-group v-model="form.level">
  96. <el-radio label="1">一级账号</el-radio>
  97. <el-radio label="2">二级账号</el-radio>
  98. <el-radio label="3">三级账号</el-radio>
  99. </el-radio-group>
  100. </el-form-item>
  101. <el-form-item>
  102. <el-button type="primary" size="mini" @click="onSubmit('form')"
  103. >保存</el-button
  104. >
  105. </el-form-item>
  106. </el-form>
  107. </el-dialog>
  108. </div>
  109. </template>
  110. <script>
  111. import { mapState, mapGetters, createNamespacedHelpers } from "vuex";
  112. import { listRole } from "@/api/system/role";
  113. const { mapActions: role_relation } = createNamespacedHelpers("role_relation");
  114. export default {
  115. name: "index",
  116. props: {},
  117. components: {},
  118. data: function () {
  119. return {
  120. // 遮罩层
  121. loading: true,
  122. // 显示搜索条件
  123. showSearch: true,
  124. // 总条数
  125. total: 0,
  126. // 角色表格数据
  127. roleList: [],
  128. // 查询参数
  129. queryParams: {
  130. pageNum: 1,
  131. pageSize: 10,
  132. roleName: undefined,
  133. },
  134. dialog: { title: "账号关联", show: false },
  135. // 账号关联
  136. form: {},
  137. rules: {
  138. level: [
  139. { required: true, message: "请选择账号等级", trigger: "change" },
  140. ],
  141. },
  142. };
  143. },
  144. created() {
  145. this.getList();
  146. this.getDicts("sys_normal_disable").then((response) => {
  147. this.statusOptions = response.data;
  148. });
  149. },
  150. methods: {
  151. ...role_relation(["query", "update"]),
  152. /** 查询角色列表 */
  153. getList() {
  154. this.loading = true;
  155. listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
  156. (response) => {
  157. this.roleList = response.rows;
  158. this.total = response.total;
  159. this.loading = false;
  160. }
  161. );
  162. },
  163. /** 搜索按钮操作 */
  164. handleQuery() {
  165. this.queryParams.pageNum = 1;
  166. this.getList();
  167. },
  168. /** 重置按钮操作 */
  169. resetQuery() {
  170. this.dateRange = [];
  171. this.resetForm("queryForm");
  172. this.handleQuery();
  173. },
  174. // 账号等级关联
  175. async toRelation(data) {
  176. // 查询该角色关联信息
  177. let res = await this.query();
  178. if (this.$checkRes(res)) {
  179. let arr = {
  180. id: res.data.id,
  181. roleName: data.roleName,
  182. roleKey: data.roleKey,
  183. };
  184. let relation = res.data.relation.find((i) => i.role == data.roleKey);
  185. if (relation) arr.level = relation.level;
  186. this.$set(this, `form`, arr);
  187. this.dialog = { title: "账号关联", show: true };
  188. }
  189. },
  190. // 保存
  191. onSubmit(formName) {
  192. this.$refs[formName].validate(async (valid) => {
  193. if (valid) {
  194. let data = {
  195. id: this.form.id,
  196. relation: [{ role: this.form.roleKey, level: this.form.level }],
  197. };
  198. let res = await this.update(data);
  199. if (res.code === 200) {
  200. this.$message({ type: `success`, message: res.msg });
  201. this.toClose();
  202. } else {
  203. this.$message({ type: `error`, message: res.msg });
  204. }
  205. } else {
  206. console.log("error submit!!");
  207. return false;
  208. }
  209. });
  210. },
  211. // 账号关联关闭
  212. toClose() {
  213. this.dialog = { title: "账号关联", show: false };
  214. this.getList();
  215. },
  216. },
  217. computed: {
  218. ...mapGetters(["roles"]),
  219. },
  220. metaInfo() {
  221. return { title: this.$route.meta.title };
  222. },
  223. watch: {
  224. test: {
  225. deep: true,
  226. immediate: true,
  227. handler(val) {},
  228. },
  229. },
  230. };
  231. </script>
  232. <style lang="scss" scoped>
  233. .main {
  234. padding: 25px 30px 30px;
  235. }
  236. </style>