祥兆质量前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

324 lines
11 KiB

2 years ago
2 years ago
  1. <template>
  2. <el-dialog
  3. class="sl-menu-item"
  4. width="465px"
  5. :title="!dataForm.id ? buttons.add :buttons.edit"
  6. :close-on-click-modal="false"
  7. :visible.sync="visible">
  8. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
  9. <el-form-item :label="buttons.type || '类型'" prop="type">
  10. <el-radio-group v-model="dataForm.type">
  11. <el-radio v-for="(type, index) in dataForm.typeList" :label="index" :key="index">{{ type }}</el-radio>
  12. </el-radio-group>
  13. </el-form-item>
  14. <el-form-item :label="dataForm.typeList[dataForm.type] +'编号'" prop="menuId">
  15. <el-input :readonly="dataForm.id?true:false" style="width: 349px;" v-model="dataForm.menuId" ></el-input>
  16. </el-form-item>
  17. <el-form-item :label="dataForm.typeList[dataForm.type] + '名称'" prop="name">
  18. <el-input style="width: 349px;" v-model="dataForm.name" ></el-input>
  19. </el-form-item>
  20. <el-form-item :label="buttons.parentName ||'上级菜单'" prop="parentName">
  21. <el-popover
  22. ref="menuListPopover"
  23. placement="bottom-start"
  24. v-model="treeVisible"
  25. onclick="treeVisible=true"
  26. trigger="click">
  27. <el-tree
  28. :data="menuList"
  29. :props="menuListTreeProps"
  30. node-key="menuId"
  31. ref="menuListTree"
  32. @current-change="menuListTreeCurrentChangeHandle"
  33. :default-expand-all="false"
  34. :highlight-current="true"
  35. :expand-on-click-node="false">
  36. </el-tree>
  37. </el-popover>
  38. <el-input style="width: 349px;" v-model="dataForm.parentName" v-popover:menuListPopover :readonly="true" class="menu-list__input"></el-input>
  39. </el-form-item>
  40. <el-form-item v-if="dataForm.type === 1" :label="buttons.route || '菜单路由'" prop="url">
  41. <el-input style="width: 349px;" v-model="dataForm.url" placeholder="菜单路由"></el-input>
  42. </el-form-item>
  43. <el-form-item v-if="dataForm.type !== 0" :label="buttons.perms || '授权标识'" prop="perms">
  44. <el-input style="width: 349px;" v-model="dataForm.perms" placeholder="多个用逗号分隔, 如: user:list,user:create"></el-input>
  45. </el-form-item>
  46. <el-form-item v-if="dataForm.type !== 2" :label="buttons.orderNum || '排序号'" prop="orderNum">
  47. <el-input style="width: 349px;" oninput="value=value.replace(/[^\d]/g, '')" v-model="dataForm.orderNum" :min="0" ></el-input>
  48. </el-form-item>
  49. <el-form-item :label="buttons.menuType || '菜单类型'" prop="menuType">
  50. <el-select v-model="dataForm.menuType">
  51. <el-option label="pc" value="pc"></el-option>
  52. <el-option label="pda" value="pda"></el-option>
  53. </el-select>
  54. </el-form-item>
  55. <el-form-item v-if="dataForm.type !== 2" label="菜单图标" prop="icon">
  56. <el-row>
  57. <el-col :span="22">
  58. <el-popover
  59. ref="iconListPopover"
  60. placement="bottom-start"
  61. trigger="click"
  62. popper-class="mod-menu__icon-popover">
  63. <div class="mod-menu__icon-inner">
  64. <div class="mod-menu__icon-list">
  65. <el-button
  66. v-for="(item, index) in iconList"
  67. :key="index"
  68. @click="iconActiveHandle(item)"
  69. :class="{ 'is-active': item === dataForm.icon }">
  70. <icon-svg :name="item"></icon-svg>
  71. </el-button>
  72. </div>
  73. </div>
  74. </el-popover>
  75. <el-input style="width: 349px;" v-model="dataForm.icon" v-popover:iconListPopover :readonly="true" class="icon-list__input"></el-input>
  76. </el-col>
  77. </el-row>
  78. </el-form-item>
  79. </el-form>
  80. <span slot="footer" class="dialog-footer">
  81. <el-button type="primary" @click="dataFormSubmit()">{{ buttons.submit || '确定' }}</el-button>
  82. <el-button type="primary" @click="visible = false">{{ buttons.close || '关闭' }}</el-button>
  83. </span>
  84. </el-dialog>
  85. </template>
  86. <script>
  87. import { treeDataTranslate } from '@/utils'
  88. import Icon from '@/icons'
  89. import {
  90. searchFunctionButtonList,
  91. } from "@/api/sysLanguage.js"
  92. export default {
  93. data () {
  94. var validateUrl = (rule, value, callback) => {
  95. if (this.dataForm.type === 1 && !/\S/.test(value)) {
  96. callback(new Error('菜单URL不能为空'))
  97. } else {
  98. callback()
  99. }
  100. }
  101. return {
  102. visible: false,
  103. treeVisible: false,
  104. dataForm: {
  105. id: 0,
  106. type: 1,
  107. typeList: ['目录', '菜单', '按钮'],
  108. name: '',
  109. parentId: 0,
  110. parentName: '',
  111. url: '',
  112. perms: '',
  113. orderNum: 0,
  114. icon: '',
  115. iconList: [],
  116. menuType: '',
  117. menuId:'',
  118. typeName:'名称'
  119. },
  120. dataRule: {
  121. name: [
  122. { required: true, message: '菜单名称不能为空', trigger: 'blur' }
  123. ],
  124. parentName: [
  125. { required: true, message: '上级菜单不能为空', trigger: 'change' }
  126. ],
  127. url: [
  128. { validator: validateUrl, trigger: 'blur' }
  129. ]
  130. },
  131. buttons: {
  132. cz: '操作',
  133. add: '添加',
  134. edit: '编辑',
  135. close: '关闭',
  136. submit: '确定',
  137. menuType:'菜单类型',
  138. name:'名称',
  139. parentName:'上级菜单',
  140. icon:'图标',
  141. type:'类型',
  142. menu:'菜单',
  143. button:'按钮',
  144. orderNum:'排序号',
  145. url:'菜单URL',
  146. perms:'授权标识',
  147. helpFile : '帮助文档',
  148. language:'语言',
  149. route:'菜单路由',
  150. type1: '目录',
  151. type2: '菜单',
  152. type3: '按钮',
  153. code:'编号'
  154. },
  155. menuList: [],
  156. menuListTreeProps: {
  157. label: 'name',
  158. children: 'children'
  159. }
  160. }
  161. },
  162. created () {
  163. this.iconList = Icon.getNameList()
  164. this.getFunctionButtonList()
  165. },
  166. methods: {
  167. init (id) {
  168. this.dataForm.id = id || 0
  169. this.$http({
  170. url: this.$http.adornUrl('/sys/menu/select'),
  171. method: 'get',
  172. params: this.$http.adornParams()
  173. }).then(({data}) => {
  174. this.menuList = treeDataTranslate(data.menuList, 'menuId')
  175. console.log( this.menuList)
  176. }).then(() => {
  177. this.visible = true
  178. this.$nextTick(() => {
  179. this.$refs['dataForm'].resetFields()
  180. })
  181. }).then(() => {
  182. if (!this.dataForm.id) {
  183. // 新增
  184. this.menuListTreeSetCurrentNode()
  185. } else {
  186. // 修改
  187. this.$http({
  188. url: this.$http.adornUrl(`/sys/menu/info/${this.dataForm.id}`),
  189. method: 'get',
  190. params: this.$http.adornParams()
  191. }).then(({data}) => {
  192. this.dataForm.id = data.menu.menuId
  193. this.dataForm.type = data.menu.type
  194. this.dataForm.name = data.menu.name
  195. this.dataForm.parentId = data.menu.parentId
  196. this.dataForm.url = data.menu.url
  197. this.dataForm.perms = data.menu.perms
  198. this.dataForm.orderNum = data.menu.orderNum
  199. this.dataForm.icon = data.menu.icon
  200. this.dataForm.menuType = data.menu.menuType
  201. this.dataForm.menuId = data.menu.menuId
  202. this.menuListTreeSetCurrentNode()
  203. })
  204. }
  205. })
  206. },
  207. // 获取button的词典
  208. getFunctionButtonList() {
  209. let queryButton = {
  210. functionId: this.$route.meta.menuId,
  211. tableId: '*',
  212. languageCode: this.$i18n.locale,
  213. objectType: 'button'
  214. }
  215. searchFunctionButtonList(queryButton).then(({data}) => {
  216. if (data.code == 0 && data.data) {
  217. this.buttons = data.data
  218. this.typeList= [this.buttons.type1,this.buttons.type2,this.buttons.type3]
  219. }
  220. })
  221. },
  222. // 菜单树选中
  223. menuListTreeCurrentChangeHandle (data, node) {
  224. this.dataForm.parentId = data.menuId
  225. this.dataForm.parentName = data.name
  226. this.treeVisible = false
  227. },
  228. // 菜单树设置当前选中节点
  229. menuListTreeSetCurrentNode () {
  230. this.$refs.menuListTree.setCurrentKey(this.dataForm.parentId)
  231. this.dataForm.parentName = (this.$refs.menuListTree.getCurrentNode() || {})['name']
  232. },
  233. // 图标选中
  234. iconActiveHandle (iconName) {
  235. this.dataForm.icon = iconName
  236. },
  237. // 表单提交
  238. dataFormSubmit () {
  239. this.$refs['dataForm'].validate((valid) => {
  240. if (valid) {
  241. this.$http({
  242. url: this.$http.adornUrl(`/sys/menu/${!this.dataForm.id ? 'save' : 'update'}`),
  243. method: 'post',
  244. data: this.$http.adornData({
  245. 'menuId': this.dataForm.menuId,
  246. 'type': this.dataForm.type,
  247. 'name': this.dataForm.name,
  248. 'parentId': this.dataForm.parentId,
  249. 'url': this.dataForm.url,
  250. 'perms': this.dataForm.perms,
  251. 'orderNum': this.dataForm.orderNum,
  252. 'icon': this.dataForm.icon,
  253. 'menuType': this.dataForm.menuType,
  254. })
  255. }).then(({data}) => {
  256. if (data && data.code === 0) {
  257. this.$message.success('操作成功')
  258. this.visible = false
  259. this.$emit('refreshDataList')
  260. } else {
  261. this.$message.error(data.msg)
  262. }
  263. })
  264. }
  265. })
  266. }
  267. },
  268. }
  269. </script>
  270. <style lang="scss" >
  271. .mod-menu {
  272. .menu-list__input,
  273. .icon-list__input {
  274. > .el-input__inner {
  275. cursor: pointer;
  276. }
  277. }
  278. &__icon-popover {
  279. width: 458px;
  280. overflow: hidden;
  281. }
  282. &__icon-inner {
  283. width: 478px;
  284. max-height: 258px;
  285. overflow-x: hidden;
  286. overflow-y: auto;
  287. }
  288. &__icon-list {
  289. width: 458px;
  290. padding: 0;
  291. margin: -8px 0 0 -8px;
  292. > .el-button {
  293. padding: 8px;
  294. margin: 8px 0 0 8px;
  295. > span {
  296. display: inline-block;
  297. vertical-align: middle;
  298. width: 18px;
  299. height: 18px;
  300. font-size: 18px;
  301. }
  302. }
  303. }
  304. .icon-list__tips {
  305. font-size: 18px;
  306. text-align: center;
  307. color: #e6a23c;
  308. cursor: pointer;
  309. }
  310. }
  311. .el-popover {
  312. height: 50%;
  313. width: 350px;
  314. overflow:auto;
  315. }
  316. .sl-menu-item .el-form-item {
  317. margin-bottom: 5px;
  318. }
  319. </style>