index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  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="appId">
  14. <el-select v-model="queryParams.appId" placeholder="请选择所属小程序" clearable size="small">
  15. <el-option
  16. v-for="dict in appMallOptions"
  17. :key="dict.appid"
  18. :label="dict.name + '(' + dict.appid + ')'"
  19. :value="dict.appid"
  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. icon="el-icon-plus"
  33. size="mini"
  34. @click="handleAdd"
  35. v-hasPermi="['store:menu:add']"
  36. >新增</el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button
  40. type="success"
  41. icon="el-icon-edit"
  42. size="mini"
  43. :disabled="single"
  44. @click="handleUpdate"
  45. v-hasPermi="['store:menu:edit']"
  46. >修改</el-button>
  47. </el-col>
  48. <el-col :span="1.5">
  49. <el-button
  50. type="danger"
  51. icon="el-icon-delete"
  52. size="mini"
  53. :disabled="multiple"
  54. @click="handleDelete"
  55. v-hasPermi="['store:menu:remove']"
  56. >删除</el-button>
  57. </el-col>
  58. </el-row>
  59. <el-tabs type="card" v-model="activeName" @tab-click="handleClick">
  60. <el-tab-pane label="全部" name="00"></el-tab-pane>
  61. <el-tab-pane v-for="(item,index) in menuTypeOptions" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
  62. </el-tabs>
  63. <el-table height="500" border v-loading="loading" :data="menuList" @selection-change="handleSelectionChange">
  64. <el-table-column type="selection" width="55" align="center" />
  65. <el-table-column label="ID" align="center" prop="menuId" />
  66. <el-table-column label="菜单名称" align="center" prop="menuName" />
  67. <el-table-column label="小程序" align="center" prop="appId" >
  68. <template slot-scope="scope">
  69. <el-tag prop="appId" v-for="(item, index) in appMallOptions" v-if="scope.row.appId==item.appid">{{item.name}}</el-tag>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="图标" align="center" width="120">
  73. <template slot-scope="scope">
  74. <el-popover
  75. placement="right"
  76. title=""
  77. trigger="hover"
  78. >
  79. <img slot="reference" :src="scope.row.icon" width="60">
  80. <img :src="scope.row.icon" style="max-width: 120px;">
  81. </el-popover>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="是否显示" align="center" prop="isShow" >
  85. <template slot-scope="scope">
  86. <el-tag prop="isShow" v-for="(item, index) in statusOptions" v-if="scope.row.isShow==item.dictValue">{{item.dictLabel}}</el-tag>
  87. </template>
  88. </el-table-column>
  89. <el-table-column label="跳转方式" align="center" prop="linkType" width="150px" >
  90. <template slot-scope="scope">
  91. <el-tag prop="linkType" v-for="(item, index) in menuLinkTypeOptions" v-if="scope.row.linkType==item.dictValue">{{item.dictLabel}}</el-tag>
  92. </template>
  93. </el-table-column>
  94. <el-table-column label="跳转地址" align="center" prop="linkUrl" />
  95. <el-table-column label="排序" sortable align="center" prop="sort" />
  96. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  97. <template slot-scope="scope">
  98. <el-button
  99. size="mini"
  100. type="text"
  101. icon="el-icon-edit"
  102. @click="handleUpdate(scope.row)"
  103. v-hasPermi="['store:menu:edit']"
  104. >修改</el-button>
  105. <el-button
  106. size="mini"
  107. type="text"
  108. icon="el-icon-delete"
  109. @click="handleDelete(scope.row)"
  110. v-hasPermi="['store:menu:remove']"
  111. >删除</el-button>
  112. </template>
  113. </el-table-column>
  114. </el-table>
  115. <pagination
  116. v-show="total>0"
  117. :total="total"
  118. :page.sync="queryParams.pageNum"
  119. :limit.sync="queryParams.pageSize"
  120. @pagination="getList"
  121. />
  122. <!-- 添加或修改用户端菜单管理对话框 -->
  123. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  124. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  125. <el-form-item label="菜单名称" prop="menuName">
  126. <el-input v-model="form.menuName" placeholder="请输入菜单名称" />
  127. </el-form-item>
  128. <el-form-item label="图标" prop="icon">
  129. <Material v-model="imageArr" type="image" :num="1" :width="100" :height="100" />
  130. </el-form-item>
  131. <el-form-item label="跳转方式" prop="linkType">
  132. <el-select style="width: 200px" v-model="form.linkType" placeholder="请选择跳转方式" clearable size="small" >
  133. <el-option
  134. v-for="item in menuLinkTypeOptions"
  135. :key="item.dictValue"
  136. :label="item.dictLabel"
  137. :value="item.dictValue"
  138. />
  139. </el-select>
  140. </el-form-item>
  141. <el-form-item label="跳转地址" prop="linkUrl">
  142. <el-input v-model="form.linkUrl" placeholder="请输入跳转地址" />
  143. </el-form-item>
  144. <el-form-item label="排序号" prop="sort">
  145. <el-input-number v-model="form.sort" :min="1" :max="100" />
  146. </el-form-item>
  147. <el-form-item label="菜单类型" prop="menuType">
  148. <el-select style="width: 200px" v-model="form.menuType" placeholder="请选择菜单类型" clearable size="small" >
  149. <el-option
  150. v-for="item in menuTypeOptions"
  151. :key="item.dictValue"
  152. :label="item.dictLabel"
  153. :value="item.dictValue"
  154. />
  155. </el-select>
  156. </el-form-item>
  157. <el-form-item label="小程序" prop="appId">
  158. <el-select style="width: 200px" v-model="form.appId" placeholder="请选择所属小程序" clearable size="small" >
  159. <el-option
  160. v-for="dict in appMallOptions"
  161. :key="dict.appid"
  162. :label="dict.name + '(' + dict.appid + ')'"
  163. :value="dict.appid"
  164. />
  165. </el-select>
  166. </el-form-item>
  167. <el-form-item label="状态" prop="isShow">
  168. <el-radio-group v-model="form.isShow">
  169. <el-radio v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictValue">{{dict.dictLabel}}</el-radio>
  170. </el-radio-group>
  171. </el-form-item>
  172. </el-form>
  173. <div slot="footer" class="dialog-footer">
  174. <el-button type="primary" @click="submitForm">确 定</el-button>
  175. <el-button @click="cancel">取 消</el-button>
  176. </div>
  177. </el-dialog>
  178. </div>
  179. </template>
  180. <script>
  181. import { listMenu, getMenu, delMenu, addMenu, updateMenu, exportMenu } from "@/api/hisStore/menu";
  182. import {list as getAppMallOptions} from '@/api/course/coursePlaySourceConfig';
  183. import Material from '@/components/Material'
  184. export default {
  185. name: "Menu",
  186. components: {
  187. Material,
  188. },
  189. watch: {
  190. imageArr: function(val) {
  191. this.form.icon = val.join(',')
  192. },
  193. },
  194. data() {
  195. return {
  196. appMallOptions:[],
  197. activeName:"00",
  198. menuLinkTypeOptions:[],
  199. menuTypeOptions:[
  200. {"dictLabel": "主菜单",
  201. "dictValue": "1"},
  202. {"dictLabel": "养生有道",
  203. "dictValue": "2"},
  204. {"dictLabel": "个人中心",
  205. "dictValue": "3"},
  206. {"dictLabel": "主菜单-热销榜",
  207. "dictValue": "4"}
  208. ],
  209. statusOptions:[],
  210. imageArr:[],
  211. // 遮罩层
  212. loading: true,
  213. // 选中数组
  214. ids: [],
  215. // 非单个禁用
  216. single: true,
  217. // 非多个禁用
  218. multiple: true,
  219. // 显示搜索条件
  220. showSearch: true,
  221. // 总条数
  222. total: 0,
  223. // 用户端菜单管理表格数据
  224. menuList: [],
  225. // 弹出层标题
  226. title: "",
  227. // 是否显示弹出层
  228. open: false,
  229. // 查询参数
  230. queryParams: {
  231. pageNum: 1,
  232. pageSize: 10,
  233. menuName: null,
  234. menuType: null,
  235. icon: null,
  236. isShow: null,
  237. },
  238. // 表单参数
  239. form: {},
  240. // 表单校验
  241. rules: {
  242. menuName: [
  243. { required: true, message: "标题不能为空" }
  244. ],
  245. icon: [
  246. { required: true, message: "图标不能为空" }
  247. ],
  248. }
  249. };
  250. },
  251. created() {
  252. this.getDicts("menu_link_type").then((response) => {
  253. this.menuLinkTypeOptions = response.data;
  254. });
  255. this.getDicts("common_status").then((response) => {
  256. this.statusOptions = response.data;
  257. });
  258. this.getAppMallOptions();
  259. this.getList();
  260. },
  261. methods: {
  262. // 获取小程序选项列表
  263. getAppMallOptions() {
  264. getAppMallOptions({pageNum:1,pageSize:100,isMall:1}).then(response => {
  265. this.appMallOptions = response.rows;
  266. })
  267. },
  268. handleClick(tab,event){
  269. this.activeName=tab.name;
  270. if(tab.name=="00"){
  271. this.queryParams.menuType=null;
  272. }else{
  273. this.queryParams.menuType=tab.name;
  274. }
  275. this.getList()
  276. },
  277. /** 查询用户端菜单管理列表 */
  278. getList() {
  279. this.loading = true;
  280. listMenu(this.queryParams).then(response => {
  281. this.menuList = response.rows;
  282. this.total = response.total;
  283. this.loading = false;
  284. });
  285. },
  286. // 取消按钮
  287. cancel() {
  288. this.open = false;
  289. this.reset();
  290. },
  291. // 表单重置
  292. reset() {
  293. this.form = {
  294. menuId: null,
  295. menuName: null,
  296. icon: null,
  297. isShow: "1",
  298. linkType: "1",
  299. linkUrl:null,
  300. createTime: null,
  301. updateTime: null,
  302. sort:1,
  303. menuType:null,
  304. };
  305. this.imageArr=[];
  306. this.resetForm("form");
  307. },
  308. /** 搜索按钮操作 */
  309. handleQuery() {
  310. this.queryParams.pageNum = 1;
  311. this.getList();
  312. },
  313. /** 重置按钮操作 */
  314. resetQuery() {
  315. this.resetForm("queryForm");
  316. this.handleQuery();
  317. },
  318. // 多选框选中数据
  319. handleSelectionChange(selection) {
  320. this.ids = selection.map(item => item.menuId)
  321. this.single = selection.length!==1
  322. this.multiple = !selection.length
  323. },
  324. /** 新增按钮操作 */
  325. handleAdd() {
  326. this.reset();
  327. this.open = true;
  328. this.title = "添加菜单管理";
  329. },
  330. /** 修改按钮操作 */
  331. handleUpdate(row) {
  332. this.reset();
  333. const menuId = row.menuId || this.ids
  334. getMenu(menuId).then(response => {
  335. this.form = response.data;
  336. if(response.data.isShow!=null){
  337. this.form.isShow = response.data.isShow.toString();
  338. }
  339. if(response.data.linkType!=null){
  340. this.form.linkType = response.data.linkType.toString();
  341. }
  342. if(response.data.menuType!=null){
  343. this.form.menuType = response.data.menuType.toString();
  344. }
  345. if(this.form.icon!=null){
  346. this.imageArr=this.form.icon.split(",");
  347. }
  348. this.open = true;
  349. this.title = "修改菜单管理";
  350. });
  351. },
  352. /** 提交按钮 */
  353. submitForm() {
  354. this.$refs["form"].validate(valid => {
  355. if (valid) {
  356. if (this.form.menuId != null) {
  357. updateMenu(this.form).then(response => {
  358. if (response.code === 200) {
  359. this.msgSuccess("修改成功");
  360. this.open = false;
  361. this.getList();
  362. }
  363. });
  364. } else {
  365. addMenu(this.form).then(response => {
  366. if (response.code === 200) {
  367. this.msgSuccess("新增成功");
  368. this.open = false;
  369. this.getList();
  370. }
  371. });
  372. }
  373. }
  374. });
  375. },
  376. /** 删除按钮操作 */
  377. handleDelete(row) {
  378. const menuIds = row.menuId || this.ids;
  379. this.$confirm('是否确认删除用户端菜单管理编号为"' + menuIds + '"的数据项?', "警告", {
  380. confirmButtonText: "确定",
  381. cancelButtonText: "取消",
  382. type: "warning"
  383. }).then(function() {
  384. return delMenu(menuIds);
  385. }).then(() => {
  386. this.getList();
  387. this.msgSuccess("删除成功");
  388. }).catch(function() {});
  389. },
  390. /** 导出按钮操作 */
  391. handleExport() {
  392. const queryParams = this.queryParams;
  393. this.$confirm('是否确认导出所有用户端菜单管理数据项?', "警告", {
  394. confirmButtonText: "确定",
  395. cancelButtonText: "取消",
  396. type: "warning"
  397. }).then(function() {
  398. return exportMenu(queryParams);
  399. }).then(response => {
  400. this.download(response.msg);
  401. }).catch(function() {});
  402. }
  403. }
  404. };
  405. </script>