navigation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div class="navigation">
  3. <!-- 头部细节部分 -->
  4. <div class="title">
  5. <el-row>
  6. <el-col :span="24">
  7. <div class="top">
  8. <el-button type="success" style="margin-left: 1%;" @click="addNew">新增</el-button>
  9. <el-button type="success" style="margin-left: 1%;" @click="openChange">修改</el-button>
  10. <el-button type="success" style="margin-left: 1%;" @click="DeleteMenu">删除</el-button>
  11. </div>
  12. </el-col>
  13. </el-row>
  14. </div>
  15. <!-- 头部细节部分结束 -->
  16. <el-row>
  17. <el-col :span="24">
  18. <div class="grid-content bg-purple-dark">
  19. <el-tree
  20. v-loading="loading"
  21. :data="menuList"
  22. show-checkbox
  23. default-expand-all
  24. check-strictly
  25. node-key="id"
  26. ref="tree"
  27. highlight-current
  28. @check="handleCheckChange"
  29. :props="defaultProps">
  30. </el-tree>
  31. </div>
  32. </el-col>
  33. </el-row>
  34. <!-- 新增菜单 -->
  35. <el-dialog
  36. @close="handleEditDialogClose"
  37. :visible.sync="addUserList">
  38. <div class="tou">导航--添加</div>
  39. <div class="line"></div>
  40. <el-form
  41. label-position="right"
  42. label-width="100px"
  43. :model="formMenuList">
  44. <el-form-item label="导航名称">
  45. <el-input v-model.string="formMenuList.name" auto-complete="off" placeholder="请输入导航名称"></el-input>
  46. </el-form-item>
  47. <el-form-item label="父级id">
  48. <el-input v-model.string="formMenuList.parentId" auto-complete="off" placeholder="请输入父级节点id"></el-input>
  49. </el-form-item>
  50. <el-form-item label="导航级数">
  51. <el-input v-model.string="formMenuList.level" auto-complete="off" placeholder="请输入导航级数"></el-input>
  52. </el-form-item>
  53. <el-form-item label="路由路径">
  54. <el-input v-model.string="formMenuList.goPageUrl" auto-complete="off" placeholder="请输入路由路径"></el-input>
  55. </el-form-item>
  56. <el-form-item label="是否首页展示">
  57. <el-select v-model="formMenuList.homePageFlag" placeholder="是否首页展示" style="width: 100%">
  58. <el-option
  59. v-for="item in option"
  60. :key="item.value"
  61. :label="item.label"
  62. :value="item.value">
  63. </el-option>
  64. </el-select>
  65. </el-form-item>
  66. <el-form-item label="菜单排序">
  67. <el-input v-model="formMenuList.homePageOrder" auto-complete="off" placeholder="请输入菜单排序"></el-input>
  68. </el-form-item>
  69. </el-form>
  70. <div slot="footer" class="dialog-footer">
  71. <el-button @click="addUserList = false" type="info">取 消</el-button>
  72. <el-button type="primary" @click="addData">新 增</el-button>
  73. </div>
  74. </el-dialog>
  75. <!-- 修改菜单 -->
  76. <el-dialog
  77. @close="handleEditDialogClose"
  78. :visible.sync="changeUser">
  79. <div class="tou">导航--修改</div>
  80. <div class="line"></div>
  81. <el-form
  82. label-position="right"
  83. label-width="100px"
  84. :model="formMenuchangeList">
  85. <el-form-item label="导航名称">
  86. <el-input v-model.string="formMenuchangeList.name" auto-complete="off" placeholder="请输入导航名称"></el-input>
  87. </el-form-item>
  88. <el-form-item label="本级导航id">
  89. <el-input v-model.string="formMenuchangeList.id" auto-complete="off" placeholder=" 请输入父级节点id"></el-input>
  90. </el-form-item>
  91. <el-form-item label="路由路径">
  92. <el-input v-model.string="formMenuchangeList.goPageUrl" auto-complete="off" placeholder="请输入路由路径"></el-input>
  93. </el-form-item>
  94. <el-form-item label="是否首页展示">
  95. <el-select v-model="formMenuchangeList.homePageFlag" placeholder="是否首页展示" style="width: 100%">
  96. <el-option
  97. v-for="item in option"
  98. :key="item.value"
  99. :label="item.label"
  100. :value="item.value">
  101. </el-option>
  102. </el-select>
  103. </el-form-item>
  104. <el-form-item label="菜单排序">
  105. <el-input v-model="formMenuchangeList.homePageOrder" auto-complete="off" placeholder="请输入菜单排序"></el-input>
  106. </el-form-item>
  107. </el-form>
  108. <div slot="footer" class="dialog-footer">
  109. <el-button @click="changeUser = false" type="info">取 消</el-button>
  110. <el-button type="primary" @click="changeData">修 改</el-button>
  111. </div>
  112. </el-dialog>
  113. </div>
  114. </template>
  115. <script type="text/javascript">
  116. export default{
  117. data() {
  118. return {
  119. // loading: true,
  120. option: [{
  121. value: '1',
  122. label: '首页不展示'
  123. }, {
  124. value: '2',
  125. label: '首页展示'
  126. }],
  127. formMenuList: {
  128. "name": "",
  129. "parentId": "",
  130. "level": "",
  131. "goPageUrl": "",
  132. "homePageFlag": "",
  133. "homePageOrder": ""
  134. },
  135. formMenuchangeList: {
  136. "id": "",
  137. "name": "",
  138. "goPageUrl": "",
  139. "homePageFlag": "",
  140. "homePageOrder": ""
  141. },
  142. menuList: [],
  143. dataList: '',
  144. addUserList: false,
  145. changeUser: false,
  146. defaultProps: {
  147. children: 'childList',
  148. label: 'name'
  149. },
  150. }
  151. },
  152. created() {
  153. this.loadData();
  154. },
  155. methods: {
  156. async loadData() {
  157. const response = await this.$http.get(`app/menu`);
  158. if (response.data.code === 1) {
  159. // console.log(response.data.responseData)
  160. this.menuList = response.data.responseData;
  161. this.loading = false;
  162. }
  163. },
  164. // 选择中的时候获取当前Id
  165. handleCheckChange(data, checked, indeterminate) {
  166. this.dataList = data;
  167. },
  168. // 增加菜单
  169. addNew() {
  170. this.addUserList = true;
  171. this.formMenuList.parentId = this.dataList.id;
  172. },
  173. // 新增导航
  174. async addData() {
  175. const formData = new FormData();
  176. formData.append('name', this.formMenuList.name);
  177. formData.append('parentId', this.formMenuList.parentId);
  178. formData.append('level', this.formMenuList.level);
  179. formData.append('goPageUrl', this.formMenuList.goPageUrl);
  180. formData.append('homePageFlag', this.formMenuList.homePageFlag);
  181. formData.append('homePageOrder', this.formMenuList.homePageOrder);
  182. const response = await this.$http.post(`app/menu`,formData);
  183. if(response.data.code === 1) {
  184. this.loadData();
  185. this.addUserList = false;
  186. this.$message({
  187. type: 'success',
  188. message: '添加成功'
  189. });
  190. }else {
  191. this.$message({
  192. type: 'error',
  193. message: '添加失败'
  194. });
  195. }
  196. },
  197. // 修改前判断
  198. openChange() {
  199. if(this.dataList == '') {
  200. this.$message.error('请选择要修改的单条数据');
  201. this.changeUser = false;
  202. return;
  203. };
  204. if(this.dataList.homePageFlag == 1) {
  205. this.formMenuchangeList.homePageFlag = '首页不展示'
  206. };
  207. if(this.dataList.homePageFlag == 2) {
  208. this.formMenuchangeList.homePageFlag = '首页展示'
  209. };
  210. this.changeUser = true;
  211. this.formMenuchangeList.id = this.dataList.id;
  212. this.formMenuchangeList.name = this.dataList.name;
  213. this.formMenuchangeList.goPageUrl = this.dataList.goPageUrl;
  214. if(this.dataList.homePageOrder == null) {
  215. this.formMenuchangeList.homePageOrder = '';
  216. }else {
  217. this.formMenuchangeList.homePageOrder = this.dataList.homePageOrder;
  218. }
  219. // this.formMenuchangeList.homePageFlag = this.dataList.homePageFlag;
  220. console.log(this.formMenuchangeList.homePageOrder)
  221. },
  222. // 修改导航
  223. async changeData () {
  224. if(this.formMenuchangeList.homePageFlag == '首页不展示') {
  225. this.formMenuchangeList.homePageFlag = 1
  226. };
  227. if(this.formMenuchangeList.homePageFlag == '首页展示') {
  228. this.formMenuchangeList.homePageFlag = 2
  229. };
  230. const formData = new FormData();
  231. formData.append('name', this.formMenuchangeList.name);
  232. formData.append('id', this.formMenuchangeList.id);
  233. formData.append('goPageUrl', this.formMenuchangeList.goPageUrl);
  234. formData.append('homePageFlag', this.formMenuchangeList.homePageFlag);
  235. formData.append('homePageOrder', this.formMenuchangeList.homePageOrder);
  236. const response = await this.$http.put(`app/menu`,formData);
  237. if(response.data.code === 1) {
  238. this.loadData();
  239. this.changeUser = false;
  240. this.$message({
  241. type: 'success',
  242. message: '修改成功'
  243. });
  244. }else {
  245. this.$message({
  246. type: 'error',
  247. message: '修改失败'
  248. });
  249. }
  250. },
  251. // 删除导航
  252. DeleteMenu() {
  253. if(this.dataList == '') {
  254. this.$message.error('请选择要删除的单条数据');
  255. return;
  256. }
  257. this.formMenuchangeList.menuId = this.dataList.id;
  258. this.$confirm('是否删除该分类', '提示' ,{
  259. confirmButtonText: '确定',
  260. cancelButtonText: '取消',
  261. type: 'warning'
  262. }).then(async () => {
  263. const response = await this.$http.put(`app/menu/${this.formMenuchangeList.menuId}`);
  264. if(response.data.code === 1) {
  265. this.loadData();
  266. this.dataList = '';
  267. this.$message({
  268. type: 'success',
  269. message: '删除成功'
  270. });
  271. }else {
  272. this.$message({
  273. type: 'error',
  274. message: '删除失败'
  275. });
  276. }
  277. }).catch(() => {
  278. this.$message({ type: 'info', message: '已取消删除'});
  279. });
  280. },
  281. // 清空表单数据
  282. handleEditDialogClose() {
  283. for (var key in this.formMenuchangeList) {
  284. this.formMenuchangeList[key] = '';
  285. }
  286. for (var key in this.formMenuList) {
  287. this.formMenuList[key] = "";
  288. }
  289. this.$refs.tree.setCheckedKeys([]);
  290. this.dataList = '';
  291. },
  292. }
  293. };
  294. </script>
  295. <style>
  296. .navigation {
  297. border: 1px solid #d9d9d9;
  298. border-radius: 10px;
  299. }
  300. .navigation .title {
  301. font-size: 5px;
  302. margin-bottom: 20px;
  303. }
  304. .navigation .top {
  305. padding-top: 20px;
  306. padding-left: 20px;
  307. }
  308. .navigation .text {
  309. display: inline-block;
  310. color: #000;
  311. font-size: 16px ;
  312. margin-left: 1%;
  313. }
  314. .navigation .input-demo {
  315. display: inline-block;
  316. width: 20%;
  317. margin-left: 1%;
  318. }
  319. .navigation .block {
  320. font-size: 5px;
  321. text-align: center;
  322. margin-top: 25px;
  323. margin-bottom: 25px;
  324. }
  325. .navigation .el-dialog {
  326. width: 60%;
  327. }
  328. .navigation .el-dialog__header, .el-dialog__body {
  329. padding: 0 20px;
  330. }
  331. .navigation .tou {
  332. font-size: 20px;
  333. height: 30px;
  334. line-height: 30px;
  335. padding-top: 15px;
  336. }
  337. .navigation .line {
  338. margin-top: 15px;
  339. margin-bottom: 15px;
  340. width: 100%;
  341. height: 2px;
  342. background-color: #d9d9d9;
  343. }
  344. .navigation .xinxi {
  345. text-align: center;
  346. margin: 15px auto;
  347. font-size: 18px;
  348. }
  349. </style>