addon.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. <style>
  2. .table-body {
  3. padding: 20px 20px;
  4. background-color: #fff;
  5. }
  6. .table-body .top-input {
  7. margin-top: 34px;
  8. }
  9. .input-item {
  10. width: 200px;
  11. margin-right: 20px;
  12. }
  13. .input-item .el-input__inner {
  14. border-right: 0;
  15. }
  16. .input-item .el-input__inner:hover {
  17. border: 1px solid #dcdfe6;
  18. border-right: 0;
  19. outline: 0;
  20. }
  21. .input-item .el-input__inner:focus {
  22. border: 1px solid #dcdfe6;
  23. border-right: 0;
  24. outline: 0;
  25. }
  26. .input-item .el-input-group__append {
  27. background-color: #fff;
  28. border-left: 0;
  29. width: 10%;
  30. padding: 0;
  31. }
  32. .input-item .el-input-group__append .el-button {
  33. padding: 0;
  34. }
  35. .input-item .el-input-group__append .el-button {
  36. margin: 0;
  37. }
  38. /* #app .table-body .el-table .el-button {
  39. border-radius: 16px;
  40. } */
  41. .create {
  42. height: 36px;
  43. line-height: 36px;
  44. float: right;
  45. color: #BCBCBC;
  46. margin-left: 20px;
  47. }
  48. .name {
  49. cursor: pointer;
  50. color: #49A9FF;
  51. }
  52. .el-input-group__append {
  53. /* background-color: #fff; */
  54. }
  55. /* 卡片 */
  56. .plugin-list {
  57. margin: 0 0 0 -20px;
  58. /* padding-right: 100px; */
  59. display: flex;
  60. flex-wrap: wrap;
  61. }
  62. .plugin-list .plugin-item {
  63. width: 20%;
  64. min-width: 400px;
  65. }
  66. .plugin-item {
  67. border: 1px solid #ebebeb;
  68. background: #FFFFFF;
  69. box-shadow: 3px 5px 15px rgba(80, 80, 80, 0.16);
  70. opacity: 1;
  71. border-radius: 5px;
  72. padding: 20px;
  73. margin: 0 0 20px 20px;
  74. transition: 250ms;
  75. position: relative;
  76. /* min-width: 300px; */
  77. }
  78. .plugin-item .item-status {
  79. position: absolute;
  80. top: 0;
  81. right: 0;
  82. width: 94px;
  83. height: 30px;
  84. background: #E8EAEC;
  85. opacity: 1;
  86. border-radius: 0px 5px 0px 5px;
  87. font-size: 14px;
  88. font-family: Microsoft YaHei;
  89. font-weight: 400;
  90. line-height: 30px;
  91. color: #9398A4;
  92. text-align: center;
  93. }
  94. .item-status-permanent {
  95. width: 94px;
  96. }
  97. .item-status-effective {
  98. width: 164px;
  99. }
  100. .plugin-item .item-info {
  101. display: flex;
  102. align-items: center;
  103. }
  104. /* .plugin-item .item-info .item-right{
  105. min-width: 500px;
  106. } */
  107. .plugin-item .item-btns {
  108. display: flex;
  109. align-items: center;
  110. justify-content: flex-end;
  111. margin-top: 12px;
  112. }
  113. .plugin-item .mall-logo {
  114. width: 70px;
  115. height: 70px;
  116. margin-right: 12px;
  117. }
  118. .plugin-item .mall-logo img {
  119. width: 100%;
  120. height: 100%;
  121. display: block;
  122. border-radius: 50%;
  123. }
  124. .plugin-item .display-name {
  125. font-size: 18pt;
  126. margin-top: 10px;
  127. margin-bottom: 4px;
  128. font-family: Microsoft YaHei;
  129. font-weight: bold;
  130. line-height: 30px;
  131. color: #3F495D;
  132. opacity: 1;
  133. width: 200px;
  134. white-space: nowrap;
  135. overflow: hidden;
  136. text-overflow: ellipsis;
  137. }
  138. .plugin-item .name {
  139. color: #909399;
  140. }
  141. .plugin-item:hover {
  142. cursor: pointer;
  143. border-color: #bfddff;
  144. }
  145. /* .plugin-item:hover .display-name {
  146. color: #409EFF;
  147. } */
  148. .plugin-item .plugin-option-btn {
  149. height: 25px;
  150. width: 25px;
  151. font-size: 12px;
  152. padding: 0;
  153. }
  154. .plugin-item .detail-option.detail-option {
  155. color: #909399;
  156. background: #F2F6FC;
  157. }
  158. .plugin-item .detail-option:hover {
  159. color: #fff;
  160. background: #909399;
  161. }
  162. </style>
  163. <div id="app" v-cloak>
  164. <el-card shadow="never" style="border:0;min-width: 1200px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  165. <div slot="header">
  166. <div>
  167. <span>应用菜单管理</span>
  168. </div>
  169. </div>
  170. <div class="table-body">
  171. <template>
  172. <div>
  173. <el-table :data="tableData" style="width: 100%;margin-bottom: 20px;" row-key="id" stripe lazy :load="loadData" :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
  174. <el-table-column prop="title" label="名称" width="180">
  175. <template slot-scope="scope">
  176. <span style="margin-left: 10px">{{ scope.row.title }}
  177. </span>
  178. </template>
  179. </el-table-column>
  180. <el-table-column prop="url" label="路由">
  181. <template slot-scope="scope">
  182. <span style="margin-left: 10px">{{ scope.row.url }}</span>
  183. </template>
  184. </el-table-column>
  185. <el-table-column prop="status" label="状态">
  186. <template slot-scope="scope">
  187. <el-switch v-model="scope.row.status" :inactive-value="0" :active-value="1" active-color="#409EFF" inactive-color="#C0CCDA" @change="handleUpdate(scope.row)">
  188. </el-switch>
  189. </template>
  190. </el-table-column>
  191. <el-table-column
  192. prop="sort"
  193. label="序号"
  194. width="200">
  195. <template slot-scope="scope">
  196. <div v-if="sort_id != scope.row.id">
  197. <el-tooltip class="item" effect="dark" content="排序" placement="top">
  198. <span>{{scope.row.sort}}</span>
  199. </el-tooltip>
  200. <el-button class="edit-sort" type="text" @click="edit(scope.row,'sort')">
  201. <img src="resources/img/mall/order/edit.png" alt="">
  202. </el-button>
  203. </div>
  204. <div style="display: flex;align-items: center" v-else>
  205. <el-input style="min-width: 70px" type="number" size="mini" class="change" v-model="sort"></el-input>
  206. <el-button class="change-quit" type="text" style="color: #F56C6C;padding: 0 5px" icon="el-icon-error" circle @click="cancelEdit('sort')"></el-button>
  207. <el-button class="change-success" type="text" style="margin-left: 0;color: #67C23A;padding: 0 5px" icon="el-icon-success" circle @click="changeValue(scope.row)">
  208. </el-button>
  209. </div>
  210. </template>
  211. </el-table-column>
  212. </el-table>
  213. </div>
  214. </template>
  215. </div>
  216. <el-dialog title="新增" :visible.sync="dialogFormVisible_add_0">
  217. <el-form :model="form0" :rules="rules" ref="form0" @close="handleClose('form0')">
  218. <el-form-item label="父级菜单" :label-width="formLabelWidth">
  219. <el-select v-model="parent_title" placeholder="请选择" @change="handleChange">
  220. <el-option v-for="item,k in parent_list" :key="k" :label="item" :value="k">
  221. </el-option>
  222. </el-select>
  223. </el-form-item>
  224. <el-form-item label="名称" :label-width="formLabelWidth" prop="title">
  225. <el-input v-model="form0.title" autocomplete="off"></el-input>
  226. </el-form-item>
  227. <el-form-item label="路由" :label-width="formLabelWidth" prop="url">
  228. <el-input v-model="form0.url" autocomplete="off"></el-input>
  229. </el-form-item>
  230. <el-form-item label="图标" :label-width="formLabelWidth">
  231. <el-input v-model="form0.icon" autocomplete="off"></el-input>
  232. </el-form-item>
  233. <el-form-item label="开发可见" :label-width="formLabelWidth">
  234. <el-switch v-model="form0.dev" :active-value="1" :inactive-value="0"></el-switch>
  235. </el-form-item>
  236. <el-form-item label="状态" :label-width="formLabelWidth">
  237. <el-switch v-model="form0.status" :active-value="1" :inactive-value="0"></el-switch>
  238. </el-form-item>
  239. </el-form>
  240. <div slot="footer" class="dialog-footer">
  241. <el-button @click="dialogFormVisible_add_0 = false">取 消</el-button>
  242. <el-button type="primary" @click="postAdd0('form0')">确 定</el-button>
  243. </div>
  244. </el-dialog>
  245. <el-dialog title="新增" :visible.sync="dialogFormVisible_add">
  246. <el-form :model="form" :rules="rules" ref="form" @close="handleClose('form')">
  247. <el-form-item label="父级名称" :label-width="formLabelWidth">
  248. <el-select v-model="parent_title" placeholder="请选择" @change="handleChange">
  249. <el-option v-for="item,k in parent_list" :key="k" :label="item" :value="k">
  250. </el-option>
  251. </el-select>
  252. </el-form-item>
  253. <el-form-item label="名称" :label-width="formLabelWidth" prop="title">
  254. <el-input v-model="form.title" autocomplete="off"></el-input>
  255. </el-form-item>
  256. <el-form-item label="路由" :label-width="formLabelWidth" prop="url">
  257. <el-input v-model="form.url" autocomplete="off"></el-input>
  258. </el-form-item>
  259. <el-form-item label="图标" :label-width="formLabelWidth">
  260. <el-input v-model="form.icon" autocomplete="off"></el-input>
  261. </el-form-item>
  262. <el-form-item label="开发可见" :label-width="formLabelWidth">
  263. <el-switch v-model="form.dev" :active-value="1" :inactive-value="0"></el-switch>
  264. </el-form-item>
  265. <el-form-item label="状态" :label-width="formLabelWidth">
  266. <el-switch v-model="form.status" :active-value="1" :inactive-value="0"></el-switch>
  267. </el-form-item>
  268. </el-form>
  269. <div slot="footer" class="dialog-footer">
  270. <el-button @click="dialogFormVisible_add = false">取 消</el-button>
  271. <el-button type="primary" @click="postAdd('form')">确 定</el-button>
  272. </div>
  273. </el-dialog>
  274. <el-dialog title="编辑" :visible.sync="dialogFormVisible_edit">
  275. <el-form :model="form" :rules="rules" ref="form" @close="handleClose('form')">
  276. <el-form-item label="父级名称" :label-width="formLabelWidth">
  277. <el-select v-model="parent_title" placeholder="请选择" @change="handleChange">
  278. <el-option v-for="item,k in parent_list" :key="k" :label="item" :value="k">
  279. </el-option>
  280. </el-select>
  281. </el-form-item>
  282. <el-form-item label="名称" :label-width="formLabelWidth" prop="title">
  283. <el-input v-model="form.title" autocomplete="off"></el-input>
  284. </el-form-item>
  285. <el-form-item label="路由" :label-width="formLabelWidth" prop="url">
  286. <el-input v-model="form.url" autocomplete="off"></el-input>
  287. </el-form-item>
  288. <el-form-item label="图标" :label-width="formLabelWidth">
  289. <el-input v-model="form.icon" autocomplete="off"></el-input>
  290. </el-form-item>
  291. <el-form-item label="开发可见" :label-width="formLabelWidth">
  292. <el-switch v-model="form.dev" :active-value="1" :inactive-value="0"></el-switch>
  293. </el-form-item>
  294. <el-form-item label="状态" :label-width="formLabelWidth">
  295. <el-switch v-model="form.status" :active-value="1" :inactive-value="0"></el-switch>
  296. </el-form-item>
  297. </el-form>
  298. <div slot="footer" class="dialog-footer">
  299. <el-button @click="dialogFormVisible_edit = false">取 消</el-button>
  300. <el-button type="primary" @click="postEdit('form')">确 定</el-button>
  301. </div>
  302. </el-dialog>
  303. </el-card>
  304. </div>
  305. <script>
  306. new Vue({
  307. el: '#app',
  308. data() {
  309. return {
  310. activeName: "1",
  311. tableData: [],
  312. dialogFormVisible_edit: false,
  313. dialogFormVisible_add: false,
  314. dialogFormVisible_add_0: false,
  315. options: [],
  316. parent_list: [],
  317. parent_title: '',
  318. form0: {
  319. id: '',
  320. parent_title: '',
  321. title: '',
  322. app_id: "backend",
  323. cate_id: '3',
  324. addons_name: '',
  325. is_addon: 0,
  326. pid: 0,
  327. url: '',
  328. icon: '',
  329. dev: 0,
  330. sort: 999,
  331. status: 0,
  332. },
  333. rules: {
  334. title: [{
  335. required: true,
  336. message: '请输入名称',
  337. trigger: 'blur'
  338. },
  339. {
  340. min: 1,
  341. max: 20,
  342. message: '长度在 1 到 20 个字符',
  343. trigger: 'blur'
  344. }
  345. ],
  346. url: [{
  347. required: true,
  348. message: '请输入路由',
  349. trigger: 'blur'
  350. }, ],
  351. },
  352. form: {
  353. id: '',
  354. title: '',
  355. app_id: "backend",
  356. cate_id: '3',
  357. addons_name: '',
  358. is_addon: 0,
  359. pid: 0,
  360. url: '',
  361. icon: '',
  362. dev: 0,
  363. sort: 999,
  364. status: 0,
  365. },
  366. formLabelWidth: '120px',
  367. cate_id: 1,
  368. sort: 0,
  369. sort_id: 0,
  370. }
  371. },
  372. created() {
  373. this.loadList({});
  374. },
  375. methods: {
  376. loadList(params) {
  377. params['r'] = 'admin/menu/addon';
  378. this.$request({
  379. params: params,
  380. }).then(e => {
  381. if (e.data.code == 0) {
  382. if(e.data.data.menus){
  383. let menus = e.data.data.menus;
  384. for(var i in menus) {
  385. console.log(menus[i]['child'].length);
  386. if(menus[i]['child'].length!=0){
  387. menus[i].hasChildren = true;
  388. }
  389. }
  390. this.tableData = menus;
  391. }
  392. }
  393. }).catch(e => {});
  394. },
  395. handleChange(value) {
  396. this.form.pid = value;
  397. this.form0.pid = value;
  398. },
  399. handleClick(tab, event) {
  400. this.loadList({
  401. cate_id: tab.name
  402. });
  403. this.form.cate_id = tab.name
  404. this.form0.cate_id = tab.name
  405. this.cate_id = tab.name
  406. },
  407. handleEdit(index, row) {
  408. this.form.id = row.id
  409. this.$request({
  410. params: {
  411. r: 'admin/menu/edit',
  412. id: row.id,
  413. type: 'edit'
  414. },
  415. }).then(e => {
  416. if(e.data.code==0){
  417. this.dialogFormVisible_edit = true;
  418. this.parent_title = e.data.data.parent_title;
  419. this.parent_list = e.data.data.list;
  420. this.form = e.data.data.menus;
  421. this.form.cate_id = e.data.data.menus.cate_id.toString();
  422. }else{
  423. this.$message.error(e.data.msg);
  424. }
  425. console.log(e.data.data);
  426. }).catch(e => {});
  427. },
  428. handleAdd(index, row) {
  429. console.log(row);
  430. this.dialogFormVisible_add = true;
  431. this.$request({
  432. params: {
  433. r: 'admin/menu/edit',
  434. id: row.id,
  435. type: 'add',
  436. },
  437. }).then(e => {
  438. if (e.data.code == 0) {
  439. this.parent_title = e.data.data.parent_title;
  440. this.form.pid = row.id;
  441. this.parent_list = e.data.data.list;
  442. }
  443. console.log(e.data.data);
  444. }).catch(e => {});
  445. },
  446. handleAdds() {
  447. this.dialogFormVisible_add_0 = true;
  448. this.$request({
  449. params: {
  450. r:'admin/menu/add',
  451. id:'',
  452. type:'add',
  453. },
  454. }).then(e => {
  455. if (e.data.code == 0) {
  456. this.parent_title = e.data.data.parent_title;
  457. this.parent_list = e.data.data.list;
  458. }
  459. console.log(e.data.data);
  460. }).catch(e => {
  461. });
  462. },
  463. postEdit(formName){
  464. this.$refs[formName].validate((valid) => {
  465. console.log(valid);
  466. if(valid){
  467. this.form.cate_id = this.activeName;
  468. this.$request({
  469. method:"post",
  470. params: {
  471. r:'admin/menu/edit',
  472. },
  473. data:this.form
  474. }).then(e => {
  475. if(e.data.code==0){
  476. if(this.form.id){
  477. this.dialogFormVisible_edit = false;
  478. }else{
  479. this.dialogFormVisible_add = false;
  480. }
  481. this.$message({
  482. message: e.data.msg,
  483. type: 'success'
  484. });
  485. }else{
  486. this.$message.error(e.data.msg);
  487. }
  488. }).catch(e => {
  489. });
  490. }
  491. });
  492. },
  493. postAdd(formName) {
  494. this.$refs[formName].validate((valid) => {
  495. console.log(valid);
  496. if (valid) {
  497. this.form.cate_id = this.activeName;
  498. this.$request({
  499. method: "post",
  500. params: {
  501. r: 'admin/menu/add',
  502. },
  503. data: this.form
  504. }).then(e => {
  505. if (e.data.code == 0) {
  506. if (this.form.id) {
  507. this.dialogFormVisible_edit = false;
  508. } else {
  509. this.dialogFormVisible_add = false;
  510. }
  511. this.handleClose(formName);
  512. this.$message({
  513. message: e.data.msg,
  514. type: 'success'
  515. });
  516. }else{
  517. this.$message.error(e.data.msg);
  518. }
  519. }).catch(e => {});
  520. }
  521. });
  522. },
  523. postAdd0(formName) {
  524. this.$refs[formName].validate((valid) => {
  525. if (valid) {
  526. this.form.cate_id = this.activeName;
  527. this.$request({
  528. method: "post",
  529. params: {
  530. r: 'admin/menu/add',
  531. },
  532. data: this.form0
  533. }).then(e => {
  534. if (e.data.code == 0) {
  535. if (this.form.id) {
  536. this.dialogFormVisible_edit = false;
  537. } else {
  538. this.dialogFormVisible_add = false;
  539. }
  540. this.handleClose(formName);
  541. this.$message({
  542. message: e.data.msg,
  543. type: 'success'
  544. });
  545. }else{
  546. this.$message.error(e.data.msg);
  547. }
  548. }).catch(e => {});
  549. }
  550. });
  551. },
  552. handleDelete(index, row) {
  553. console.log(row);
  554. this.form.id = row.id
  555. this.$request({
  556. params: {
  557. r: 'admin/menu/del',
  558. id: row.id,
  559. status: -1,
  560. },
  561. }).then(e => {
  562. if (e.data.code == 0) {
  563. this.$message({
  564. message: e.data.msg,
  565. type: 'success'
  566. });
  567. location.reload();
  568. }
  569. }).catch(e => {});
  570. },
  571. handleUpdate(row) {
  572. console.log(row);
  573. this.form.id = row.id
  574. this.$request({
  575. params: {
  576. r:'admin/menu/update-status',
  577. id:row.id,
  578. status:row.status,
  579. },
  580. }).then(e => {
  581. if (e.data.code == 0) {
  582. this.$message({
  583. message: e.data.msg,
  584. type: 'success'
  585. });
  586. }
  587. }).catch(e => {});
  588. },
  589. loadData(tree, treeNode, resolve) {
  590. this.$request({
  591. params: {
  592. r: 'admin/menu/addon',
  593. pid: tree.id,
  594. cate_id: this.cate_id,
  595. },
  596. }).then(e => {
  597. if (e.data.code == 0) {
  598. let menus = e.data.data.menus;
  599. for(var i in menus) {
  600. console.log(menus[i]['child'].length);
  601. if(menus[i]['child'].length!=0){
  602. menus[i].hasChildren = true;
  603. }
  604. }
  605. resolve(menus);
  606. }
  607. }).catch(e => {});
  608. },
  609. handleClose(formName){
  610. this.$refs[formName].resetFields();
  611. },
  612. changeValue(row){
  613. this.$request({
  614. params: {
  615. r:'admin/menu/update-sort',
  616. id:row.id,
  617. sort:this.sort,
  618. },
  619. }).then(e => {
  620. this.$message({
  621. message: e.data.msg,
  622. type: 'success'
  623. });
  624. row.sort = this.sort;
  625. this.sort_id=0;
  626. }).catch(e => {
  627. });
  628. },
  629. edit(row, type) {
  630. switch (type) {
  631. case 'sort':
  632. this.sort = row.sort;
  633. this.sort_id = row.id;
  634. break;
  635. }
  636. },
  637. cancelEdit(type) {
  638. switch (type) {
  639. case 'sort':
  640. this.sort = 0;
  641. this.sort_id = 0;
  642. break;
  643. }
  644. },
  645. },
  646. });
  647. </script>