index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. ],
  207. statusOptions:[],
  208. imageArr:[],
  209. // 遮罩层
  210. loading: true,
  211. // 选中数组
  212. ids: [],
  213. // 非单个禁用
  214. single: true,
  215. // 非多个禁用
  216. multiple: true,
  217. // 显示搜索条件
  218. showSearch: true,
  219. // 总条数
  220. total: 0,
  221. // 用户端菜单管理表格数据
  222. menuList: [],
  223. // 弹出层标题
  224. title: "",
  225. // 是否显示弹出层
  226. open: false,
  227. // 查询参数
  228. queryParams: {
  229. pageNum: 1,
  230. pageSize: 10,
  231. menuName: null,
  232. menuType: null,
  233. icon: null,
  234. isShow: null,
  235. },
  236. // 表单参数
  237. form: {},
  238. // 表单校验
  239. rules: {
  240. menuName: [
  241. { required: true, message: "标题不能为空" }
  242. ],
  243. icon: [
  244. { required: true, message: "图标不能为空" }
  245. ],
  246. }
  247. };
  248. },
  249. created() {
  250. this.getDicts("menu_link_type").then((response) => {
  251. this.menuLinkTypeOptions = response.data;
  252. });
  253. this.getDicts("common_status").then((response) => {
  254. this.statusOptions = response.data;
  255. });
  256. this.getAppMallOptions();
  257. this.getList();
  258. },
  259. methods: {
  260. // 获取小程序选项列表
  261. getAppMallOptions() {
  262. getAppMallOptions({pageNum:1,pageSize:100,isMall:1}).then(response => {
  263. this.appMallOptions = response.rows;
  264. })
  265. },
  266. handleClick(tab,event){
  267. this.activeName=tab.name;
  268. if(tab.name=="00"){
  269. this.queryParams.menuType=null;
  270. }else{
  271. this.queryParams.menuType=tab.name;
  272. }
  273. this.getList()
  274. },
  275. /** 查询用户端菜单管理列表 */
  276. getList() {
  277. this.loading = true;
  278. listMenu(this.queryParams).then(response => {
  279. this.menuList = response.rows;
  280. this.total = response.total;
  281. this.loading = false;
  282. });
  283. },
  284. // 取消按钮
  285. cancel() {
  286. this.open = false;
  287. this.reset();
  288. },
  289. // 表单重置
  290. reset() {
  291. this.form = {
  292. menuId: null,
  293. menuName: null,
  294. icon: null,
  295. isShow: "1",
  296. linkType: "1",
  297. linkUrl:null,
  298. createTime: null,
  299. updateTime: null,
  300. sort:1,
  301. menuType:null,
  302. };
  303. this.imageArr=[];
  304. this.resetForm("form");
  305. },
  306. /** 搜索按钮操作 */
  307. handleQuery() {
  308. this.queryParams.pageNum = 1;
  309. this.getList();
  310. },
  311. /** 重置按钮操作 */
  312. resetQuery() {
  313. this.resetForm("queryForm");
  314. this.handleQuery();
  315. },
  316. // 多选框选中数据
  317. handleSelectionChange(selection) {
  318. this.ids = selection.map(item => item.menuId)
  319. this.single = selection.length!==1
  320. this.multiple = !selection.length
  321. },
  322. /** 新增按钮操作 */
  323. handleAdd() {
  324. this.reset();
  325. this.open = true;
  326. this.title = "添加菜单管理";
  327. },
  328. /** 修改按钮操作 */
  329. handleUpdate(row) {
  330. this.reset();
  331. const menuId = row.menuId || this.ids
  332. getMenu(menuId).then(response => {
  333. this.form = response.data;
  334. if(response.data.isShow!=null){
  335. this.form.isShow = response.data.isShow.toString();
  336. }
  337. if(response.data.linkType!=null){
  338. this.form.linkType = response.data.linkType.toString();
  339. }
  340. if(response.data.menuType!=null){
  341. this.form.menuType = response.data.menuType.toString();
  342. }
  343. if(this.form.icon!=null){
  344. this.imageArr=this.form.icon.split(",");
  345. }
  346. this.open = true;
  347. this.title = "修改菜单管理";
  348. });
  349. },
  350. /** 提交按钮 */
  351. submitForm() {
  352. this.$refs["form"].validate(valid => {
  353. if (valid) {
  354. if (this.form.menuId != null) {
  355. updateMenu(this.form).then(response => {
  356. if (response.code === 200) {
  357. this.msgSuccess("修改成功");
  358. this.open = false;
  359. this.getList();
  360. }
  361. });
  362. } else {
  363. addMenu(this.form).then(response => {
  364. if (response.code === 200) {
  365. this.msgSuccess("新增成功");
  366. this.open = false;
  367. this.getList();
  368. }
  369. });
  370. }
  371. }
  372. });
  373. },
  374. /** 删除按钮操作 */
  375. handleDelete(row) {
  376. const menuIds = row.menuId || this.ids;
  377. this.$confirm('是否确认删除用户端菜单管理编号为"' + menuIds + '"的数据项?', "警告", {
  378. confirmButtonText: "确定",
  379. cancelButtonText: "取消",
  380. type: "warning"
  381. }).then(function() {
  382. return delMenu(menuIds);
  383. }).then(() => {
  384. this.getList();
  385. this.msgSuccess("删除成功");
  386. }).catch(function() {});
  387. },
  388. /** 导出按钮操作 */
  389. handleExport() {
  390. const queryParams = this.queryParams;
  391. this.$confirm('是否确认导出所有用户端菜单管理数据项?', "警告", {
  392. confirmButtonText: "确定",
  393. cancelButtonText: "取消",
  394. type: "warning"
  395. }).then(function() {
  396. return exportMenu(queryParams);
  397. }).then(response => {
  398. this.download(response.msg);
  399. }).catch(function() {});
  400. }
  401. }
  402. };
  403. </script>