index.vue 12 KB

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