Rap 原分销系统代码Web
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

253 wiersze
10KB

  1. <template>
  2. <div class="app-container">
  3. <!--工具栏-->
  4. <div class="head-container">
  5. <div v-if="crud.props.searchToggle">
  6. <!-- 搜索 -->
  7. <el-input v-model="query.blurry" clearable size="small" placeholder="模糊搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
  8. <date-range-picker v-model="query.createTime" class="date-item" />
  9. <rrOperation />
  10. </div>
  11. <crudOperation :permission="permission" />
  12. </div>
  13. <!--表单渲染-->
  14. <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="580px">
  15. <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="80px">
  16. <el-form-item label="菜单类型" prop="type">
  17. <el-radio-group v-model="form.type" size="mini" style="width: 178px">
  18. <el-radio-button label="0">目录</el-radio-button>
  19. <el-radio-button label="1">菜单</el-radio-button>
  20. <el-radio-button label="2">按钮</el-radio-button>
  21. </el-radio-group>
  22. </el-form-item>
  23. <el-form-item v-show="form.type.toString() !== '2'" label="菜单图标" prop="icon">
  24. <el-popover
  25. placement="bottom-start"
  26. width="450"
  27. trigger="click"
  28. @show="$refs['iconSelect'].reset()"
  29. >
  30. <IconSelect ref="iconSelect" @selected="selected" />
  31. <el-input slot="reference" v-model="form.icon" style="width: 450px;" placeholder="点击选择图标" readonly>
  32. <svg-icon v-if="form.icon" slot="prefix" :icon-class="form.icon" class="el-input__icon" style="height: 32px;width: 16px;" />
  33. <i v-else slot="prefix" class="el-icon-search el-input__icon" />
  34. </el-input>
  35. </el-popover>
  36. </el-form-item>
  37. <el-form-item v-show="form.type.toString() !== '2'" label="外链菜单" prop="iFrame">
  38. <el-radio-group v-model="form.iFrame" size="mini">
  39. <el-radio-button label="true">是</el-radio-button>
  40. <el-radio-button label="false">否</el-radio-button>
  41. </el-radio-group>
  42. </el-form-item>
  43. <el-form-item v-show="form.type.toString() === '1'" label="菜单缓存" prop="cache">
  44. <el-radio-group v-model="form.cache" size="mini">
  45. <el-radio-button label="true">是</el-radio-button>
  46. <el-radio-button label="false">否</el-radio-button>
  47. </el-radio-group>
  48. </el-form-item>
  49. <el-form-item v-show="form.type.toString() !== '2'" label="菜单可见" prop="hidden">
  50. <el-radio-group v-model="form.hidden" size="mini">
  51. <el-radio-button label="false">是</el-radio-button>
  52. <el-radio-button label="true">否</el-radio-button>
  53. </el-radio-group>
  54. </el-form-item>
  55. <el-form-item v-if="form.type.toString() !== '2'" label="菜单标题" prop="title">
  56. <el-input v-model="form.title" :style=" form.type.toString() === '0' ? 'width: 450px' : 'width: 178px'" placeholder="菜单标题" />
  57. </el-form-item>
  58. <el-form-item v-if="form.type.toString() === '2'" label="按钮名称" prop="title">
  59. <el-input v-model="form.title" placeholder="按钮名称" style="width: 178px;" />
  60. </el-form-item>
  61. <el-form-item v-show="form.type.toString() !== '0'" label="权限标识" prop="permission">
  62. <el-input v-model="form.permission" :disabled="form.iFrame.toString() === 'true'" placeholder="权限标识" style="width: 178px;" />
  63. </el-form-item>
  64. <el-form-item v-if="form.type.toString() !== '2'" label="路由地址" prop="path">
  65. <el-input v-model="form.path" placeholder="路由地址" style="width: 178px;" />
  66. </el-form-item>
  67. <el-form-item label="菜单排序" prop="menuSort">
  68. <el-input-number v-model.number="form.menuSort" :min="0" :max="999" controls-position="right" style="width: 178px;" />
  69. </el-form-item>
  70. <el-form-item v-show="form.iFrame.toString() !== 'true' && form.type.toString() === '1'" label="组件名称" prop="componentName">
  71. <el-input v-model="form.componentName" style="width: 178px;" placeholder="匹配组件内Name字段" />
  72. </el-form-item>
  73. <el-form-item v-show="form.iFrame.toString() !== 'true' && form.type.toString() === '1'" label="组件路径" prop="component">
  74. <el-input v-model="form.component" style="width: 178px;" placeholder="组件路径" />
  75. </el-form-item>
  76. <el-form-item label="上级类目" prop="pid">
  77. <treeselect
  78. v-model="form.pid"
  79. :options="menus"
  80. :load-options="loadMenus"
  81. style="width: 450px;"
  82. placeholder="选择上级类目"
  83. />
  84. </el-form-item>
  85. </el-form>
  86. <div slot="footer" class="dialog-footer">
  87. <el-button type="text" @click="crud.cancelCU">取消</el-button>
  88. <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
  89. </div>
  90. </el-dialog>
  91. <!--表格渲染-->
  92. <el-table
  93. ref="table"
  94. v-loading="crud.loading"
  95. lazy
  96. :load="getMenus"
  97. :data="crud.data"
  98. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  99. row-key="id"
  100. @select="crud.selectChange"
  101. @select-all="crud.selectAllChange"
  102. @selection-change="crud.selectionChangeHandler"
  103. >
  104. <el-table-column type="selection" width="55" />
  105. <el-table-column :show-overflow-tooltip="true" label="菜单标题" width="125px" prop="title" />
  106. <el-table-column prop="icon" label="图标" align="center" width="60px">
  107. <template slot-scope="scope">
  108. <svg-icon :icon-class="scope.row.icon ? scope.row.icon : ''" />
  109. </template>
  110. </el-table-column>
  111. <el-table-column prop="menuSort" align="center" label="排序">
  112. <template slot-scope="scope">
  113. {{ scope.row.menuSort }}
  114. </template>
  115. </el-table-column>
  116. <el-table-column :show-overflow-tooltip="true" prop="permission" label="权限标识" />
  117. <el-table-column :show-overflow-tooltip="true" prop="component" label="组件路径" />
  118. <el-table-column prop="iFrame" label="外链" width="75px">
  119. <template slot-scope="scope">
  120. <span v-if="scope.row.iFrame">是</span>
  121. <span v-else>否</span>
  122. </template>
  123. </el-table-column>
  124. <el-table-column prop="cache" label="缓存" width="75px">
  125. <template slot-scope="scope">
  126. <span v-if="scope.row.cache">是</span>
  127. <span v-else>否</span>
  128. </template>
  129. </el-table-column>
  130. <el-table-column prop="hidden" label="可见" width="75px">
  131. <template slot-scope="scope">
  132. <span v-if="scope.row.hidden">否</span>
  133. <span v-else>是</span>
  134. </template>
  135. </el-table-column>
  136. <el-table-column prop="createTime" label="创建日期" width="135px" />
  137. <el-table-column v-if="checkPer(['admin','menu:edit','menu:del'])" label="操作" width="130px" align="center" fixed="right">
  138. <template slot-scope="scope">
  139. <udOperation
  140. :data="scope.row"
  141. :permission="permission"
  142. msg="确定删除吗,如果存在下级节点则一并删除,此操作不能撤销!"
  143. />
  144. </template>
  145. </el-table-column>
  146. </el-table>
  147. </div>
  148. </template>
  149. <script>
  150. import crudMenu from '@/api/system/menu'
  151. import IconSelect from '@/components/IconSelect'
  152. import Treeselect from '@riophae/vue-treeselect'
  153. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  154. import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
  155. import CRUD, { presenter, header, form, crud } from '@crud/crud'
  156. import rrOperation from '@crud/RR.operation'
  157. import crudOperation from '@crud/CRUD.operation'
  158. import udOperation from '@crud/UD.operation'
  159. import DateRangePicker from '@/components/DateRangePicker'
  160. // crud交由presenter持有
  161. const defaultForm = { id: null, title: null, menuSort: 999, path: null, component: null, componentName: null, iFrame: false, roles: [], pid: 0, icon: null, cache: false, hidden: false, type: 0, permission: null }
  162. export default {
  163. name: 'Menu',
  164. components: { Treeselect, IconSelect, crudOperation, rrOperation, udOperation, DateRangePicker },
  165. cruds() {
  166. return CRUD({ title: '菜单', url: 'api/menus', crudMethod: { ...crudMenu }})
  167. },
  168. mixins: [presenter(), header(), form(defaultForm), crud()],
  169. data() {
  170. return {
  171. menus: [],
  172. permission: {
  173. add: ['admin', 'menu:add'],
  174. edit: ['admin', 'menu:edit'],
  175. del: ['admin', 'menu:del']
  176. },
  177. rules: {
  178. title: [
  179. { required: true, message: '请输入标题', trigger: 'blur' }
  180. ],
  181. path: [
  182. { required: true, message: '请输入地址', trigger: 'blur' }
  183. ]
  184. }
  185. }
  186. },
  187. methods: {
  188. // 新增与编辑前做的操作
  189. [CRUD.HOOK.afterToCU](crud, form) {
  190. this.menus = []
  191. if (form.id != null) {
  192. if (form.pid === null) {
  193. form.pid = 0
  194. }
  195. this.getSupDepts(form.id)
  196. } else {
  197. this.menus.push({ id: 0, label: '顶级类目', children: null })
  198. }
  199. },
  200. getMenus(tree, treeNode, resolve) {
  201. const params = { pid: tree.id }
  202. setTimeout(() => {
  203. crudMenu.getMenus(params).then(res => {
  204. resolve(res.content)
  205. })
  206. }, 100)
  207. },
  208. getSupDepts(id) {
  209. crudMenu.getMenuSuperior(id).then(res => {
  210. const children = res.map(function(obj) {
  211. if (!obj.leaf && !obj.children) {
  212. obj.children = null
  213. }
  214. return obj
  215. })
  216. this.menus = [{ id: 0, label: '顶级类目', children: children }]
  217. })
  218. },
  219. loadMenus({ action, parentNode, callback }) {
  220. if (action === LOAD_CHILDREN_OPTIONS) {
  221. crudMenu.getMenusTree(parentNode.id).then(res => {
  222. parentNode.children = res.map(function(obj) {
  223. if (!obj.leaf) {
  224. obj.children = null
  225. }
  226. return obj
  227. })
  228. setTimeout(() => {
  229. callback()
  230. }, 100)
  231. })
  232. }
  233. },
  234. // 选中图标
  235. selected(name) {
  236. this.form.icon = name
  237. }
  238. }
  239. }
  240. </script>
  241. <style rel="stylesheet/scss" lang="scss" scoped>
  242. ::v-deep .el-input-number .el-input__inner {
  243. text-align: left;
  244. }
  245. ::v-deep .vue-treeselect__control,::v-deep .vue-treeselect__placeholder,::v-deep .vue-treeselect__single-value {
  246. height: 30px;
  247. line-height: 30px;
  248. }
  249. </style>