index.vue 6.8 KB

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