index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div class="role">
  3. <div class="tree">
  4. <treeList
  5. :data="treeListData"
  6. v-model="sourceList.pagination.tenantId"
  7. node-key="id"
  8. @change="treeChange"
  9. >
  10. </treeList>
  11. </div>
  12. <div class="content">
  13. <byTable
  14. :source="sourceList.data"
  15. :pagination="sourceList.pagination"
  16. :config="config"
  17. :loading="loading"
  18. highlight-current-row
  19. :selectConfig="selectConfig"
  20. :table-events="{
  21. //element talbe事件都能传
  22. 'select': select,
  23. }"
  24. :action-list="[
  25. {
  26. text: '权限配置',
  27. plain: true,
  28. //type: 'warning',
  29. action: () => openRoomModal(),
  30. disabled:selection.data.length != 1,
  31. },
  32. {
  33. text: '添加角色',
  34. action: () => openModal('add'),
  35. disabled:!sourceList.pagination.tenantId
  36. },
  37. ]"
  38. @get-list="getList"
  39. >
  40. <template #slotName="{ item }">
  41. {{ item.createTime }}
  42. </template>
  43. </byTable>
  44. </div>
  45. <el-dialog
  46. :title="modalType == 'add' ? '新增' : '编辑'"
  47. v-model="dialogVisible"
  48. width="500"
  49. v-loading="loading"
  50. >
  51. <byForm
  52. :formConfig="formConfig"
  53. :formOption="formOption"
  54. v-model="formData.data"
  55. :rules="rules"
  56. ref="byform"
  57. >
  58. </byForm>
  59. <template #footer>
  60. <el-button @click="dialogVisible = false" size="large"
  61. >取 消</el-button
  62. >
  63. <el-button
  64. type="primary"
  65. @click="submitForm('byform')"
  66. size="large"
  67. :loading="submitLoading">
  68. 确 定
  69. </el-button>
  70. </template>
  71. </el-dialog>
  72. <el-dialog
  73. title="权限配置"
  74. v-model="roomDialogVisible"
  75. width="500"
  76. :before-close="handleClose"
  77. v-loading="loading">
  78. <el-tree
  79. :data="treeData"
  80. :show-checkbox="true"
  81. v-model="formData.treeData"
  82. ref="tree"
  83. node-key="id"
  84. >
  85. </el-tree>
  86. <template #footer>
  87. <el-button @click="roomDialogVisible = false" size="large"
  88. >取 消</el-button
  89. >
  90. <el-button
  91. type="primary"
  92. @click="submitTree('byform')"
  93. size="large"
  94. :loading="submitLoading">
  95. 确 定
  96. </el-button>
  97. </template>
  98. </el-dialog>
  99. </div>
  100. </template>
  101. <script setup>
  102. /* eslint-disable vue/no-unused-components */
  103. import { ElMessage, ElMessageBox } from 'element-plus'
  104. import byTable from '@/components/byTable/index'
  105. import byForm from '@/components/byForm/index'
  106. import treeList from '@/components/treeList/index'
  107. import { computed, defineComponent, ref } from 'vue'
  108. const loading = ref(false)
  109. const submitLoading = ref(false)
  110. const sourceList = ref({
  111. data: [],
  112. pagination: {
  113. total: 3,
  114. pageNum: 1,
  115. pageSize: 10,
  116. },
  117. })
  118. let dialogVisible = ref(false)
  119. let roomDialogVisible = ref(false)
  120. let modalType = ref('add')
  121. let rules = ref({
  122. tenantId: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
  123. })
  124. const { proxy } = getCurrentInstance()
  125. const selectConfig = computed(() => {
  126. return [
  127. ]
  128. })
  129. const config = computed(() => {
  130. return [
  131. {
  132. type: 'selection',
  133. attrs: {
  134. label: '多选',
  135. prop: 'remark',
  136. },
  137. },
  138. {
  139. attrs: {
  140. label: '角色编码',
  141. prop: 'roleKey',
  142. },
  143. },
  144. {
  145. attrs: {
  146. label: '角色名称',
  147. prop: 'roleName',
  148. align: 'left',
  149. },
  150. },
  151. {
  152. attrs: {
  153. label: '创建时间',
  154. prop: 'createTime',
  155. },
  156. },
  157. {
  158. attrs: {
  159. label: '操作',
  160. width: '200',
  161. align: 'right',
  162. },
  163. // 渲染 el-button,一般用在最后一列。
  164. renderHTML(row) {
  165. return [
  166. {
  167. attrs: {
  168. label: '修改',
  169. type: 'primary',
  170. text: true,
  171. },
  172. el: 'button',
  173. click() {
  174. getDtl(row)
  175. },
  176. },
  177. {
  178. attrs: {
  179. label: '删除',
  180. type: 'danger',
  181. text: true,
  182. },
  183. el: 'button',
  184. click() {
  185. // 弹窗提示是否删除
  186. ElMessageBox.confirm('此操作将永久删除该数据, 是否继续?', '提示', {
  187. confirmButtonText: '确定',
  188. cancelButtonText: '取消',
  189. type: 'warning',
  190. })
  191. .then(() => {
  192. // 删除
  193. proxy.post('/tenantRole/' + row.roleId, {
  194. id: row.roleId,
  195. },'delete').then((res) => {
  196. ElMessage({
  197. message: '删除成功',
  198. type: 'success',
  199. })
  200. getList()
  201. })
  202. })
  203. },
  204. },
  205. ]
  206. },
  207. },
  208. ]
  209. })
  210. let formData = reactive({
  211. data:{},
  212. treeData:[],
  213. })
  214. const formOption = reactive({
  215. inline: true,
  216. labelWidth: 100,
  217. itemWidth: 100,
  218. rules: [],
  219. })
  220. const byform = ref(null)
  221. const treeData = ref([])
  222. const treeListData = ref([])
  223. const formConfig = computed(() => {
  224. return [
  225. {
  226. type: 'input',
  227. prop: 'roleKey',
  228. label: '角色编码',
  229. required: true,
  230. itemWidth: 100,
  231. //disabled:true,
  232. itemType: 'text',
  233. },
  234. {
  235. type: 'input',
  236. prop: 'roleName',
  237. label: '角色名称',
  238. required: true,
  239. itemWidth: 100,
  240. //disabled:true,
  241. itemType: 'text',
  242. },
  243. ]
  244. })
  245. const getTreeList = () => {
  246. proxy.post('/tenantInfo/list').then((message) => {
  247. message.map((item) => {
  248. item.label = item.enterpriseName
  249. item.id = item.tenantId
  250. item.children = []
  251. })
  252. treeListData.value = message
  253. console.log(treeListData.value)
  254. })
  255. }
  256. const getList = async (req) => {
  257. sourceList.value.pagination = { ...sourceList.value.pagination, ...req }
  258. loading.value = true
  259. proxy.get('/tenantRole/list',sourceList.value.pagination).then((message) => {
  260. console.log(message)
  261. sourceList.value.data = message.rows
  262. sourceList.value.pagination.total = message.total
  263. setTimeout(() => {
  264. loading.value = false
  265. }, 200)
  266. })
  267. }
  268. const treeChange = ((e) => {
  269. console.log(e)
  270. sourceList.value.pagination.tenantId = e.id
  271. getList({tenantId:e.id})
  272. })
  273. const openModal = () => {
  274. dialogVisible.value = true
  275. modalType.value = 'add'
  276. formData.data = {}
  277. }
  278. const TreetenantId = ref('')
  279. const selection = ref({
  280. data:[],
  281. })
  282. const select = (_selection, row) => {
  283. selection.value.data = _selection
  284. console.log(_selection.length)
  285. }
  286. const openRoomModal = () => {
  287. roomDialogVisible.value = true
  288. proxy.get('/tenantRole/roleMenuTreeSelect/' + selection.value.data[0].roleId).then((res) => {
  289. if(res.code == 200){
  290. treeData.value = res.menus
  291. formData.treeData = res.checkedKeys
  292. tree.value.setCheckedKeys(res.checkedKeys)
  293. }
  294. })
  295. }
  296. const tree = ref(null)
  297. const submitTree = () => {
  298. proxy.post('/tenantRole', {
  299. ... selection.value.data[0],
  300. menuIds:tree.value.getCheckedKeys(),
  301. },'PUT').then((res) => {
  302. ElMessage({
  303. message: '保存成功',
  304. type: 'success',
  305. })
  306. roomDialogVisible.value = false
  307. })
  308. }
  309. const submitForm = () => {
  310. byform.value.handleSubmit((valid) => {
  311. const method = modalType.value == 'add' ? 'POST' : 'PUT'
  312. console.log(method)
  313. proxy.post(
  314. '/tenantRole',
  315. {...formData.data,
  316. tenantId:sourceList.value.pagination.tenantId,
  317. roleSort:1,
  318. status:"0"},
  319. method
  320. ).then((res) => {
  321. ElMessage({
  322. message: modalType.value == 'add' ? '添加成功' : '编辑成功',
  323. type: 'success',
  324. })
  325. dialogVisible.value = false
  326. getList()
  327. })
  328. })
  329. }
  330. const getDtl = (row) => {
  331. formData.data = {...row}
  332. modalType.value = 'edit'
  333. console.log(modalType.value)
  334. dialogVisible.value = true
  335. }
  336. getTreeList()
  337. getList()
  338. </script>
  339. <style lang="scss" scoped>
  340. .role {
  341. padding: 20px;
  342. display: flex;
  343. justify-content: space-between;
  344. .tree{
  345. width: 300px;
  346. }
  347. .content{
  348. width:calc(100% - 320px);
  349. }
  350. }
  351. </style>