index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
  4. <el-form-item label="菜单名称" prop="menuName">
  5. <el-input
  6. v-model="queryParams.menuName"
  7. placeholder="请输入菜单名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="状态" prop="status">
  14. <el-select v-model="queryParams.status" placeholder="菜单状态" clearable size="small">
  15. <el-option
  16. v-for="dict in statusOptions"
  17. :key="dict.dictValue"
  18. :label="dict.dictLabel"
  19. :value="dict.dictValue"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-row :gutter="10" class="mb8">
  29. <el-col :span="1.5">
  30. <el-button
  31. type="primary"
  32. plain
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. v-hasPermi="['system:menu:add']"
  37. >新增</el-button>
  38. </el-col>
  39. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  40. </el-row>
  41. <el-table
  42. v-loading="loading"
  43. :data="menuList"
  44. row-key="menuId"
  45. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  46. >
  47. <el-table-column prop="menuName" label="菜单名称" :show-overflow-tooltip="true" width="160"></el-table-column>
  48. <el-table-column prop="icon" label="图标" align="center" width="100">
  49. <template slot-scope="scope">
  50. <svg-icon :icon-class="scope.row.icon" />
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="orderNum" label="排序" width="60"></el-table-column>
  54. <el-table-column prop="perms" label="权限标识" :show-overflow-tooltip="true"></el-table-column>
  55. <el-table-column prop="component" label="组件路径" :show-overflow-tooltip="true"></el-table-column>
  56. <el-table-column prop="status" label="状态" :formatter="statusFormat" width="80"></el-table-column>
  57. <el-table-column label="创建时间" align="center" prop="createTime">
  58. <template slot-scope="scope">
  59. <span>{{ parseTime(scope.row.createTime) }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  63. <template slot-scope="scope">
  64. <el-button size="mini"
  65. type="text"
  66. icon="el-icon-edit"
  67. @click="handleUpdate(scope.row)"
  68. v-hasPermi="['system:menu:edit']"
  69. >修改</el-button>
  70. <el-button
  71. size="mini"
  72. type="text"
  73. icon="el-icon-plus"
  74. @click="handleAdd(scope.row)"
  75. v-hasPermi="['system:menu:add']"
  76. >新增</el-button>
  77. <el-button
  78. size="mini"
  79. type="text"
  80. icon="el-icon-delete"
  81. @click="handleDelete(scope.row)"
  82. v-hasPermi="['system:menu:remove']"
  83. >删除</el-button>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. <!-- 添加或修改菜单对话框 -->
  88. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  89. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  90. <el-row>
  91. <el-col :span="24">
  92. <el-form-item label="上级菜单">
  93. <treeselect
  94. v-model="form.parentId"
  95. :options="menuOptions"
  96. :normalizer="normalizer"
  97. :show-count="true"
  98. placeholder="选择上级菜单"
  99. />
  100. </el-form-item>
  101. </el-col>
  102. <el-col :span="24">
  103. <el-form-item label="菜单类型" prop="menuType">
  104. <el-radio-group v-model="form.menuType">
  105. <el-radio label="M">目录</el-radio>
  106. <el-radio label="C">菜单</el-radio>
  107. <el-radio label="F">按钮</el-radio>
  108. </el-radio-group>
  109. </el-form-item>
  110. </el-col>
  111. <el-col :span="24">
  112. <el-form-item v-if="form.menuType != 'F'" label="菜单图标">
  113. <el-popover
  114. placement="bottom-start"
  115. width="460"
  116. trigger="click"
  117. @show="$refs['iconSelect'].reset()"
  118. >
  119. <IconSelect ref="iconSelect" @selected="selected" />
  120. <el-input slot="reference" v-model="form.icon" placeholder="点击选择图标" readonly>
  121. <svg-icon
  122. v-if="form.icon"
  123. slot="prefix"
  124. :icon-class="form.icon"
  125. class="el-input__icon"
  126. style="height: 32px;width: 16px;"
  127. />
  128. <i v-else slot="prefix" class="el-icon-search el-input__icon" />
  129. </el-input>
  130. </el-popover>
  131. </el-form-item>
  132. </el-col>
  133. <el-col :span="12">
  134. <el-form-item label="菜单名称" prop="menuName">
  135. <el-input v-model="form.menuName" placeholder="请输入菜单名称" />
  136. </el-form-item>
  137. </el-col>
  138. <el-col :span="12">
  139. <el-form-item label="显示排序" prop="orderNum">
  140. <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
  141. </el-form-item>
  142. </el-col>
  143. <el-col :span="12">
  144. <el-form-item v-if="form.menuType != 'F'" label="是否外链">
  145. <el-radio-group v-model="form.isFrame">
  146. <el-radio label="0">是</el-radio>
  147. <el-radio label="1">否</el-radio>
  148. </el-radio-group>
  149. </el-form-item>
  150. </el-col>
  151. <el-col :span="12">
  152. <el-form-item v-if="form.menuType != 'F'" label="路由地址" prop="path">
  153. <el-input v-model="form.path" placeholder="请输入路由地址" />
  154. </el-form-item>
  155. </el-col>
  156. <el-col :span="12" v-if="form.menuType == 'C'">
  157. <el-form-item label="组件路径" prop="component">
  158. <el-input v-model="form.component" placeholder="请输入组件路径" />
  159. </el-form-item>
  160. </el-col>
  161. <el-col :span="12">
  162. <el-form-item v-if="form.menuType != 'M'" label="权限标识">
  163. <el-input v-model="form.perms" placeholder="请输入权限标识" maxlength="100" />
  164. </el-form-item>
  165. </el-col>
  166. <el-col :span="12">
  167. <el-form-item v-if="form.menuType != 'F'" label="显示状态">
  168. <el-radio-group v-model="form.visible">
  169. <el-radio
  170. v-for="dict in visibleOptions"
  171. :key="dict.dictValue"
  172. :label="dict.dictValue"
  173. >{{dict.dictLabel}}</el-radio>
  174. </el-radio-group>
  175. </el-form-item>
  176. </el-col>
  177. <el-col :span="12">
  178. <el-form-item v-if="form.menuType != 'F'" label="菜单状态">
  179. <el-radio-group v-model="form.status">
  180. <el-radio
  181. v-for="dict in statusOptions"
  182. :key="dict.dictValue"
  183. :label="dict.dictValue"
  184. >{{dict.dictLabel}}</el-radio>
  185. </el-radio-group>
  186. </el-form-item>
  187. </el-col>
  188. <el-col :span="12">
  189. <el-form-item v-if="form.menuType == 'C'" label="是否缓存">
  190. <el-radio-group v-model="form.isCache">
  191. <el-radio label="0">缓存</el-radio>
  192. <el-radio label="1">不缓存</el-radio>
  193. </el-radio-group>
  194. </el-form-item>
  195. </el-col>
  196. </el-row>
  197. </el-form>
  198. <div slot="footer" class="dialog-footer">
  199. <el-button type="primary" @click="submitForm">确 定</el-button>
  200. <el-button @click="cancel">取 消</el-button>
  201. </div>
  202. </el-dialog>
  203. </div>
  204. </template>
  205. <script>
  206. import { listMenu, getMenu, delMenu, addMenu, updateMenu } from "@/api/system/menu";
  207. import Treeselect from "@riophae/vue-treeselect";
  208. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  209. import IconSelect from "@/components/IconSelect";
  210. export default {
  211. name: "Menu",
  212. components: { Treeselect, IconSelect },
  213. data() {
  214. return {
  215. // 遮罩层
  216. loading: true,
  217. // 显示搜索条件
  218. showSearch: true,
  219. // 菜单表格树数据
  220. menuList: [],
  221. // 菜单树选项
  222. menuOptions: [],
  223. // 弹出层标题
  224. title: "",
  225. // 是否显示弹出层
  226. open: false,
  227. // 显示状态数据字典
  228. visibleOptions: [],
  229. // 菜单状态数据字典
  230. statusOptions: [],
  231. // 查询参数
  232. queryParams: {
  233. menuName: undefined,
  234. visible: undefined
  235. },
  236. // 表单参数
  237. form: {},
  238. // 表单校验
  239. rules: {
  240. menuName: [
  241. { required: true, message: "菜单名称不能为空", trigger: "blur" }
  242. ],
  243. orderNum: [
  244. { required: true, message: "菜单顺序不能为空", trigger: "blur" }
  245. ],
  246. path: [
  247. { required: true, message: "路由地址不能为空", trigger: "blur" }
  248. ]
  249. }
  250. };
  251. },
  252. created() {
  253. this.getList();
  254. this.getDicts("sys_show_hide").then(response => {
  255. this.visibleOptions = response.data;
  256. });
  257. this.getDicts("sys_normal_disable").then(response => {
  258. this.statusOptions = response.data;
  259. });
  260. },
  261. methods: {
  262. // 选择图标
  263. selected(name) {
  264. this.form.icon = name;
  265. },
  266. /** 查询菜单列表 */
  267. getList() {
  268. this.loading = true;
  269. listMenu(this.queryParams).then(response => {
  270. this.menuList = this.handleTree(response.data, "menuId");
  271. this.loading = false;
  272. });
  273. },
  274. /** 转换菜单数据结构 */
  275. normalizer(node) {
  276. if (node.children && !node.children.length) {
  277. delete node.children;
  278. }
  279. return {
  280. id: node.menuId,
  281. label: node.menuName,
  282. children: node.children
  283. };
  284. },
  285. /** 查询菜单下拉树结构 */
  286. getTreeselect() {
  287. listMenu().then(response => {
  288. this.menuOptions = [];
  289. const menu = { menuId: 0, menuName: '主类目', children: [] };
  290. menu.children = this.handleTree(response.data, "menuId");
  291. this.menuOptions.push(menu);
  292. });
  293. },
  294. // 显示状态字典翻译
  295. visibleFormat(row, column) {
  296. if (row.menuType == "F") {
  297. return "";
  298. }
  299. return this.selectDictLabel(this.visibleOptions, row.visible);
  300. },
  301. // 菜单状态字典翻译
  302. statusFormat(row, column) {
  303. if (row.menuType == "F") {
  304. return "";
  305. }
  306. return this.selectDictLabel(this.statusOptions, row.status);
  307. },
  308. // 取消按钮
  309. cancel() {
  310. this.open = false;
  311. this.reset();
  312. },
  313. // 表单重置
  314. reset() {
  315. this.form = {
  316. menuId: undefined,
  317. parentId: 0,
  318. menuName: undefined,
  319. icon: undefined,
  320. menuType: "M",
  321. orderNum: undefined,
  322. isFrame: "1",
  323. isCache: "0",
  324. visible: "0",
  325. status: "0"
  326. };
  327. this.resetForm("form");
  328. },
  329. /** 搜索按钮操作 */
  330. handleQuery() {
  331. this.getList();
  332. },
  333. /** 重置按钮操作 */
  334. resetQuery() {
  335. this.resetForm("queryForm");
  336. this.handleQuery();
  337. },
  338. /** 新增按钮操作 */
  339. handleAdd(row) {
  340. this.reset();
  341. this.getTreeselect();
  342. if (row != null && row.menuId) {
  343. this.form.parentId = row.menuId;
  344. } else {
  345. this.form.parentId = 0;
  346. }
  347. this.open = true;
  348. this.title = "添加菜单";
  349. },
  350. /** 修改按钮操作 */
  351. handleUpdate(row) {
  352. this.reset();
  353. this.getTreeselect();
  354. getMenu(row.menuId).then(response => {
  355. this.form = response.data;
  356. this.open = true;
  357. this.title = "修改菜单";
  358. });
  359. },
  360. /** 提交按钮 */
  361. submitForm: function() {
  362. this.$refs["form"].validate(valid => {
  363. if (valid) {
  364. if (this.form.menuId != undefined) {
  365. updateMenu(this.form).then(response => {
  366. this.msgSuccess("修改成功");
  367. this.open = false;
  368. this.getList();
  369. });
  370. } else {
  371. addMenu(this.form).then(response => {
  372. this.msgSuccess("新增成功");
  373. this.open = false;
  374. this.getList();
  375. });
  376. }
  377. }
  378. });
  379. },
  380. /** 删除按钮操作 */
  381. handleDelete(row) {
  382. this.$confirm('是否确认删除名称为"' + row.menuName + '"的数据项?', "警告", {
  383. confirmButtonText: "确定",
  384. cancelButtonText: "取消",
  385. type: "warning"
  386. }).then(function() {
  387. return delMenu(row.menuId);
  388. }).then(() => {
  389. this.getList();
  390. this.msgSuccess("删除成功");
  391. }).catch(() => {});
  392. }
  393. }
  394. };
  395. </script>