operationModel.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <div>
  3. <el-form :model="productForm" ref="productForm" >
  4. <el-alert
  5. title="产品信息"
  6. type="info"
  7. :closable="false"
  8. style="margin-bottom: 20px"
  9. ></el-alert>
  10. <el-form-item
  11. label="产品名称"
  12. prop="name"
  13. :label-width="formLabelWidth"
  14. :rules="[{ required: true, message: '产品名称', trigger: 'blur' }]"
  15. >
  16. <el-input clearable placeholder="请输入产品名称" v-model="productForm.name" />
  17. </el-form-item>
  18. <el-form-item
  19. label="产品描述"
  20. prop="remark"
  21. :label-width="formLabelWidth"
  22. >
  23. <el-input clearable type="textarea" placeholder="请输入产品描述" v-model="productForm.remark" />
  24. </el-form-item>
  25. <el-alert
  26. title="产品权限"
  27. type="info"
  28. :closable="false"
  29. style="margin-bottom: 20px"
  30. ></el-alert>
  31. <el-form-item label="搜索" style="margin-bottom: 0;">
  32. <el-input style="width:210px"
  33. v-model.trim="seachRoleValue" clearable></el-input>
  34. <el-button style="margin-left: 10px"
  35. type="danger"
  36. @click="seachRoles">搜索</el-button>
  37. <!-- <el-button type="primary"
  38. @click="onReSetRole">重置</el-button> -->
  39. </el-form-item>
  40. <el-form-item style="max-height: 300px;overflow: hidden;overflow-y: auto;">
  41. <el-checkbox :indeterminate="isIndeterminate"
  42. @change="onCheckAll"
  43. v-model.trim="checkAll">全选</el-checkbox>
  44. <el-tree :data="data"
  45. show-checkbox
  46. node-key="id"
  47. @check="onTreeCheck"
  48. :filter-node-method="filterNode"
  49. ref="tree"
  50. accordion
  51. highlight-current
  52. :default-checked-keys="result.menuIds"
  53. :props="defaultProps">
  54. <div slot-scope="{ node, data }">
  55. {{ node.label }}
  56. <!-- <el-tag v-if="data.type == 1"
  57. effect="dark">按钮</el-tag> -->
  58. </div>
  59. </el-tree>
  60. </el-form-item>
  61. </el-form>
  62. </div>
  63. </template>
  64. <script>
  65. import { platformProductUpdate,platformProductAdd } from "./api";
  66. import { getSilder } from '@/api/silder'
  67. export default {
  68. props: ["activeRow", "pageType"],
  69. data() {
  70. return {
  71. productForm: {
  72. // menuId: "",
  73. name: "",
  74. remark: "",
  75. id: null,
  76. },
  77. menuId: [], // 存修改时设置的编号
  78. formLabelWidth: "80px",
  79. isIndeterminate: false,
  80. data: [],
  81. defaultProps: {
  82. children: 'children',
  83. label: 'label'
  84. },
  85. result: {
  86. roleName: null,
  87. roleDesc: null,
  88. },
  89. checkAll: false,
  90. splice: [],
  91. silderList: [],
  92. allChildIds: [], // 所有子编号
  93. slideCount: 0,
  94. seachRoleValue: '', //权限搜索字段
  95. filterIds: [4794, 4743, 3266, 3268, 3306, 3307, 3309, 3784, 4627]
  96. // 4229 公用权限
  97. };
  98. },
  99. mounted() {
  100. const activeRow = this.activeRow
  101. if(activeRow) {
  102. this.productForm = {
  103. name: activeRow.name,
  104. remark: activeRow.remark,
  105. id: activeRow.id,
  106. }
  107. this.menuId = activeRow.menuId ? activeRow.menuId.split(',').map(res => Number(res)) : []
  108. }
  109. if(this.pageType == 'create') {
  110. this.$refs.tree.setCheckedKeys([4229]);
  111. }
  112. this.lookSilder()
  113. },
  114. methods: {
  115. async submitInfo(str) {
  116. let tempIds = this.$refs.tree.getCheckedKeys()
  117. let halfIds = this.$refs.tree.getHalfCheckedKeys()
  118. let allIds = [...tempIds, ...halfIds]
  119. this.$refs.productForm.validate(async (_) => {
  120. if (_) {
  121. if (str == "update") {
  122. try {
  123. const res = await platformProductUpdate({
  124. name: this.productForm.name,
  125. remark: this.productForm.remark,
  126. menuId: allIds.join(','),
  127. id: this.productForm.id
  128. });
  129. this.$message.success("修改成功");
  130. this.$emit('close')
  131. } catch {}
  132. }else if(str == "create"){
  133. try {
  134. const res = await platformProductAdd({
  135. name: this.productForm.name,
  136. remark: this.productForm.remark,
  137. menuId: allIds.join(',')
  138. });
  139. this.$message.success("新建成功");
  140. this.$emit('close')
  141. } catch {}
  142. }
  143. }
  144. });
  145. },
  146. async lookSilder () {
  147. let silderList = await getSilder({ hid: 0 })
  148. let tempData = []
  149. if (silderList.code == 200) {
  150. const silderData = silderList.data || []
  151. let silderItem = []
  152. silderData.forEach(item => { // 去掉公用权限
  153. // if(item.permission != "publicAuthority") {
  154. silderItem.push(item)
  155. // }
  156. })
  157. this.silderList = silderItem
  158. tempData = this.setTableData(silderItem)
  159. console.log(tempData)
  160. this.data = tempData
  161. }
  162. if (this.pageType == 'update') {
  163. let roleData = {}
  164. // 是否是全部选中
  165. this.checkAll = this.menuId.length >= this.slideCount
  166. // 是否是半选
  167. this.isIndeterminate = this.menuId.length > 0 && this.menuId.length < this.slideCount
  168. let tSplice = this.getParent(this.menuId, tempData)
  169. roleData.menuIds = tSplice
  170. this.result = roleData
  171. } else {
  172. this.onReSet()
  173. }
  174. },
  175. onTreeCheck () {
  176. let checkTree = this.$refs.tree.getCheckedKeys()
  177. this.checkAll = checkTree.length >= this.slideCount
  178. this.isIndeterminate = checkTree.length > 0 && checkTree.length < this.slideCount
  179. },
  180. onCheckAll (val) {
  181. if (val) {
  182. // 先去掉半选
  183. this.isIndeterminate = false
  184. this.$refs.tree.setCheckedNodes(this.data)
  185. } else {
  186. this.$refs.tree.setCheckedNodes([])
  187. }
  188. },
  189. //递归获取到所有的为子级的ID
  190. getParent (checkIds, data) {
  191. let removeIds = JSON.parse(JSON.stringify(checkIds))
  192. this.getAllChildIds(data)
  193. let tempAllChildIds = this.allChildIds
  194. for (let i = checkIds.length; i > 0; i--) {
  195. if (!tempAllChildIds.includes(checkIds[i - 1])) {
  196. removeIds.splice(i - 1, 1)
  197. }
  198. }
  199. return removeIds
  200. },
  201. getAllChildIds (data) {
  202. // 获取所有最子集编号
  203. let child = this.allChildIds
  204. let tempList = []
  205. data.forEach((item, index) => {
  206. let temp = []
  207. if (item.children && item.children.length > 0) {
  208. temp = this.getAllChildIds(item.children)
  209. } else {
  210. child.push(item.id)
  211. }
  212. })
  213. },
  214. setTableData (result) {
  215. let list = []
  216. list = result.map(res => {
  217. if(!this.filterIds.includes(res.id)) {
  218. let tempList = {}
  219. tempList = {
  220. id: res.id,
  221. name: res.name,
  222. label: res.name,
  223. type: res.type,
  224. path: res.path,
  225. permission: res.permission,
  226. icon: res.icon,
  227. parentId: res.parentId
  228. }
  229. this.slideCount++
  230. if (res.sysMenus && res.sysMenus.length > 0) {
  231. tempList.children = this.setTableData(res.sysMenus)
  232. }
  233. return tempList
  234. }
  235. return null
  236. })
  237. let tempList = []
  238. list.forEach(item => {
  239. if(item) {
  240. tempList.push(item)
  241. }
  242. })
  243. return tempList
  244. },
  245. onReSet () {
  246. this.$refs.tree.setCheckedNodes([])
  247. this.result = {
  248. roleName: null,
  249. roleDesc: null,
  250. }
  251. this.isIndeterminate = false
  252. this.checkAll = false
  253. },
  254. onCancel () {
  255. this.$store.dispatch('delVisitedViews', this.$route)
  256. this.$router.push({
  257. path: '/parameter/adminManager',
  258. query: {
  259. page: this.$route.query.page
  260. }
  261. })
  262. },
  263. seachRoles () {
  264. this.$refs.tree.filter(this.seachRoleValue);
  265. },
  266. filterNode(value, data) {
  267. if (!value) return true;
  268. return data.label.indexOf(value) !== -1;
  269. },
  270. onReSetRole () {
  271. this.seachRoleValue = ''
  272. this.data = this.setTableData(this.silderList)
  273. }
  274. }
  275. };
  276. </script>
  277. <style lang="scss" scoped>
  278. .courseMask {
  279. .el-tag.el-tag--info {
  280. margin-right: 4px;
  281. }
  282. }
  283. </style>