menuRole.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class=" uni-container ">
  3. <view class="u-demo-block">
  4. <view class="u-demo-block__content">
  5. <!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
  6. <u--form :model="user" ref="form1" label-width='80'>
  7. <u-form-item label="角色名称" prop="roleName">
  8. <u--input v-model="user.roleName" :disabled="true"></u--input>
  9. </u-form-item>
  10. <u-form-item label="角色标识" prop="roleLable">
  11. <u--input v-model="user.roleLable" :disabled="true"></u--input>
  12. </u-form-item>
  13. <!-- <u-form-item label="角色" prop="appmenusIds"
  14. @click="showRole = true; hideKeyboard()">
  15. <u--input v-model="user.appmenusIds" disabled disabledColor="#ffffff" placeholder="请选择性别"
  16. ></u--input>
  17. <u-icon slot="right" name="arrow-right"></u-icon>
  18. </u-form-item> -->
  19. <u-form-item label="角色" prop="appmenusIds">
  20. <u-checkbox-group v-model="user.appmenusIds" placement="column" @change="checkboxChange">
  21. <u-checkbox activeColor="#4CB2B6" :customStyle="{marginBottom: '8px'}" v-for="(item, index) in menuAppOptions"
  22. :key="index" :label="item.menuName" :name="item.id">
  23. </u-checkbox>
  24. </u-checkbox-group>
  25. </u-form-item>
  26. </u--form>
  27. <u-button type="primary" text="提交" customStyle="height: 72rpx;width: 340rpx;margin-top: 100rpx;display: flex;align-items: center;justify-content: center;border-radius: 60rpx;background: #4CB2B6;" @click="submit"></u-button>
  28. <u-action-sheet :show="showRole " :menuAppOptions="menuAppOptions" title="请选择性别" description="如果选择保密会报错"
  29. @close="showRole = false" @select="roleSelect">
  30. </u-action-sheet>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. getMenusByRole, // 根据角色id获取角色下面的菜单
  38. assignAppRoleMenu, // 设置角色的菜单
  39. getAppMenusPage, // 获得移动端菜单分页
  40. } from '@/api/personnel_permissions';
  41. import {
  42. DICT_TYPE,
  43. getDictDatas
  44. } from "@/utils/dict";
  45. let that = null;
  46. export default {
  47. data() {
  48. return {
  49. user: {
  50. id: undefined,
  51. roleName: undefined,
  52. roleLable: undefined,
  53. },
  54. showRole: false,
  55. rules: {
  56. 'roleName': {
  57. // type: 'string',
  58. required: true,
  59. message: '用户名称不能为空',
  60. trigger: ['blur']
  61. },
  62. 'roleLable': {
  63. // type: 'string',
  64. required: true,
  65. message: '用户昵称不能为空',
  66. trigger: ['blur']
  67. },
  68. },
  69. menuAppOptions: []
  70. }
  71. },
  72. onLoad(option) {
  73. that = this
  74. let str = decodeURIComponent(option.val)
  75. if (str != "undefined") {
  76. that.user = JSON.parse(str);
  77. this.getUser(that.user.id);
  78. }
  79. },
  80. onReady() {
  81. // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  82. this.$refs.form1.setRules(this.rules)
  83. },
  84. onShow() {},
  85. methods: {
  86. async getUser(id) {
  87. // 获得角色列表
  88. getAppMenusPage({
  89. pageNo: 1,
  90. pageSize: 100,
  91. }).then(response => {
  92. // 处理 menuAppOptions 参数
  93. this.menuAppOptions = [];
  94. this.menuAppOptions.push(...response.data.list);
  95. });
  96. // 获得用户拥有的角色集合
  97. await getMenusByRole({
  98. id: id
  99. }).then(response => {
  100. // 设置选中
  101. this.user.appmenusIds = []
  102. var appmenusIds = response.data ? response.data : [];
  103. appmenusIds.map(i => {
  104. this.user.appmenusIds.push(i.id)
  105. })
  106. this.$forceUpdate()
  107. })
  108. },
  109. checkboxChange(e) {
  110. this.user.appmenusIds = e
  111. },
  112. roleSelect(e) {
  113. this.user.appmenusIds = e.name
  114. this.user.sex = e.id
  115. this.$refs.form1.validateField('userInfo.sex')
  116. },
  117. submit() {
  118. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  119. this.$refs.form1.validate().then(res => {
  120. // uni.$u.toast('校验通过')
  121. if (this.user.id !== undefined) {
  122. assignAppRoleMenu({
  123. roleId: this.user.id,
  124. menusIds: this.user.appmenusIds,
  125. }).then(response => {
  126. this.$tab.navigateBack('/pagesA/fire/personnel_permissions/index')
  127. });
  128. }
  129. }).catch(errors => {
  130. console.log(errors);
  131. // uni.$u.toast('校验失败')/
  132. })
  133. },
  134. hideKeyboard() {
  135. uni.hideKeyboard()
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .uni-container {
  142. padding: 20px;
  143. }
  144. </style>