index.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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 style="float: right; margin: -5px 0">
  169. <el-button type="primary" size="small" @click="handleAdd">新增</el-button>
  170. </div>
  171. </div>
  172. </div>
  173. <div class="table-body">
  174. <template>
  175. <div>
  176. <el-table
  177. :data="tableData"
  178. style="width: 100%;margin-bottom: 20px;"
  179. row-key="id"
  180. stripe
  181. lazy
  182. >
  183. <el-table-column
  184. prop="title"
  185. label="名称"
  186. sortable
  187. width="180">
  188. <template slot-scope="scope">
  189. <span style="margin-left: 10px" >{{ scope.row.title }}</span>
  190. </template>
  191. </el-table-column>
  192. <el-table-column
  193. prop="sort"
  194. label="排序">
  195. <template slot-scope="scope">
  196. <span style="margin-left: 10px">{{ scope.row.sort }}</span>
  197. </template>
  198. </el-table-column>
  199. <el-table-column label="操作">
  200. <template slot-scope="scope">
  201. <el-button type="text" size="mini" circle style="margin-left: 10px;margin-top: 10px"
  202. @click="handleEdit(scope.$index, scope.row)">
  203. <el-tooltip class="item" effect="dark" content="编辑" placement="top">
  204. <img src="resources/img/mall/edit.png" alt="">
  205. </el-tooltip>
  206. </el-button>
  207. <el-button v-if="scope.row.is_default== 0 " style="margin-left: 10px;margin-top: 10px" type="text"
  208. class="set-el-button"
  209. size="mini" circle @click="handleDelete(scope.$index, scope.row)">
  210. <el-tooltip class="item" effect="dark" content="删除" placement="top">
  211. <img src="resources/img/mall/del.png" alt="">
  212. </el-tooltip>
  213. </el-button>
  214. </template>
  215. </el-table-column>
  216. </el-table>
  217. </div>
  218. </template>
  219. </div>
  220. <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="dialogFormVisible_add" >
  221. <el-form :model="form" :rules="rules" ref="form" @close="handleClose('form')">
  222. <el-form-item label="名称" :label-width="formLabelWidth" prop="title">
  223. <el-input v-model="form.title" autocomplete="off"></el-input>
  224. </el-form-item>
  225. <el-form-item label="状态" :label-width="formLabelWidth">
  226. <el-switch v-model="form.status" :active-value="1" :inactive-value="0"></el-switch>
  227. </el-form-item>
  228. <el-form-item label="排序" :label-width="formLabelWidth">
  229. <el-input v-model="form.sort" autocomplete="off"></el-input>
  230. </el-form-item>
  231. <el-form-item label="权限" :label-width="formLabelWidth">
  232. <el-tree
  233. :data="tree_data"
  234. show-checkbox
  235. node-key="id"
  236. ref="tree"
  237. :default-checked-keys="checkedKey"
  238. :props="defaultProps">
  239. </el-tree>
  240. </el-form-item>
  241. </el-form>
  242. <div slot="footer" class="dialog-footer">
  243. <el-button @click="dialogFormVisible_edit = false">取 消</el-button>
  244. <el-button type="primary" @click="postAdd('form')">确 定</el-button>
  245. </div>
  246. </el-dialog>
  247. <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="dialogFormVisible_edit">
  248. <el-form :model="form" :rules="rules" ref="form" @close="handleClose('form')">
  249. <el-form-item label="名称" :label-width="formLabelWidth" prop="title">
  250. <el-input v-model="form.title" autocomplete="off"></el-input>
  251. </el-form-item>
  252. <el-form-item label="状态" :label-width="formLabelWidth">
  253. <el-switch v-model="form.status" :active-value="1" :inactive-value="0"></el-switch>
  254. </el-form-item>
  255. <el-form-item label="排序" :label-width="formLabelWidth">
  256. <el-input v-model="form.sort" autocomplete="off"></el-input>
  257. </el-form-item>
  258. <el-form-item label="权限" :label-width="formLabelWidth">
  259. <el-tabs v-model="activeName" @tab-click="handleClick">
  260. <el-tab-pane label="商城" name="2">
  261. <el-tree
  262. :data="tree_data2"
  263. show-checkbox
  264. node-key="id"
  265. ref="tree2"
  266. @check-change="checkchange1"
  267. :check-strictly="true"
  268. :default-checked-keys="checkedKey"
  269. :props="defaultProps">
  270. </el-tree>
  271. </el-tab-pane>
  272. <el-tab-pane label="应用" name="3">
  273. <el-tree
  274. :data="tree_data3"
  275. show-checkbox
  276. node-key="id"
  277. ref="tree3"
  278. :check-strictly="true"
  279. @check-change="checkchange2"
  280. :default-checked-keys="checkedKey"
  281. :props="defaultProps">
  282. </el-tree>
  283. </el-tab-pane>
  284. </el-tabs>
  285. </el-form-item>
  286. </el-form>
  287. <div slot="footer" class="dialog-footer">
  288. <el-button @click="dialogFormVisible_edit = false">取 消</el-button>
  289. <el-button type="primary" @click="postAdd('form')">确 定</el-button>
  290. </div>
  291. </el-dialog>
  292. </el-card>
  293. </div>
  294. <script>
  295. new Vue({
  296. el: '#app',
  297. data() {
  298. return {
  299. activeName:"2",
  300. tree_data2:[],
  301. tree_data3:[],
  302. tableData: [],
  303. dialogFormVisible_edit:false,
  304. dialogFormVisible_add:false,
  305. parent_list: [],
  306. items: [],
  307. parent_title:'',
  308. form: {
  309. id:'',
  310. title:'',
  311. pid:0,
  312. sort:999,
  313. status:1,
  314. item_ids:[]
  315. },
  316. rules:{
  317. title: [
  318. { required: true, message: '请输入名称', trigger: 'blur' },
  319. { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
  320. ],
  321. },
  322. formLabelWidth: '120px',
  323. defaultProps: {
  324. children: 'children',
  325. label: 'label'
  326. },
  327. tree_data:[],
  328. checkedKey:[],
  329. title:'新增'
  330. }
  331. },
  332. created() {
  333. this.loadList({});
  334. },
  335. methods: {
  336. checkchange1(data, checked, indeterminate){
  337. this.checkchange(data,checked,indeterminate,'tree2')
  338. },
  339. checkchange2(data, checked, indeterminate){
  340. this.checkchange(data,checked,indeterminate,'tree3')
  341. },
  342. checkchange(data, checked, indeterminate,type){
  343. console.log(type)
  344. let checkid = []
  345. console.log(data,'data555555555')
  346. if(checked == true){
  347. checkid.push(data.id)
  348. if(data.children && data.children.length > 0){
  349. data.children.forEach((it,i)=>{
  350. checkid.push(it.id)
  351. if(it.children && it.children.length > 0){
  352. it.children.forEach((item,index)=>{
  353. checkid.push(item.id)
  354. if(item.children && item.children.length > 0){
  355. item.children.forEach((item1,index1)=>{
  356. checkid.push(item1.id)
  357. })
  358. }
  359. })
  360. }
  361. })
  362. }
  363. this.checkedKey = checkid
  364. }else{
  365. let treenodes=[]
  366. if(type == 'tree2'){
  367. treenodes=this.$refs.tree2.getCheckedKeys()
  368. }else{
  369. treenodes=this.$refs.tree3.getCheckedKeys()
  370. }
  371. treenodes.forEach((v,i)=>{
  372. if(data.children && data.children.length >0){
  373. data.children.forEach((v1,i1)=>{
  374. if(v== v1.id){
  375. if(type == 'tree2'){
  376. this.$refs.tree2.setChecked(v,false);
  377. }else{
  378. this.$refs.tree3.setChecked(v,false);
  379. }
  380. }
  381. })
  382. if(data.children.children && data.children.children.length >0){
  383. data.children.children.forEach((v2,i2)=>{
  384. if(v== v2.id){
  385. if(type == 'tree2'){
  386. this.$refs.tree2.setChecked(v,false);
  387. }else{
  388. this.$refs.tree3.setChecked(v,false);
  389. }
  390. }
  391. })
  392. if(data.children.children.children && data.children.children.children.length >0){
  393. data.children.children.children.forEach((v3,i3)=>{
  394. if(v== v3.id){
  395. if(type == 'tree2'){
  396. this.$refs.tree2.setChecked(v,false);
  397. }else{
  398. this.$refs.tree3.setChecked(v,false);
  399. }
  400. }
  401. })
  402. }
  403. }
  404. }
  405. })
  406. }
  407. },
  408. loadList(params) {
  409. params['r'] = 'mall/role/index';
  410. this.$request({
  411. params: params,
  412. }).then(e => {
  413. if(e.data.code==0){
  414. if(e.data.data.list){
  415. this.tableData = e.data.data.list;
  416. }
  417. }
  418. }).catch(e => {
  419. });
  420. },
  421. handleChange(value){
  422. this.form.pid = value;
  423. },
  424. handleAdd()
  425. {
  426. this.title='新增';
  427. this.dialogFormVisible_edit = true;
  428. this.$request({
  429. params: {
  430. r:'mall/role/edit',
  431. id:''
  432. },
  433. }).then(e => {
  434. if(e.data.code==0){
  435. this.form.id = '';
  436. this.tree_data2 = e.data.data.item_list2;
  437. this.tree_data3 = e.data.data.item_list3;
  438. this.checkedKey = e.data.data.checked_key;
  439. }
  440. }).catch(e => {
  441. });
  442. },
  443. handleAdds(index, row)
  444. {
  445. this.title='新增';
  446. this.dialogFormVisible_edit = true;
  447. this.$request({
  448. params: {
  449. r:'mall/role/edit',
  450. id:row.id
  451. },
  452. }).then(e => {
  453. if(e.data.code==0){
  454. this.form.pid = row.id;
  455. this.parent_list = e.data.data.list;
  456. this.tree_data = e.data.data.item_list;
  457. this.parent_title =e.data.data.role.title;
  458. }
  459. }).catch(e => {
  460. });
  461. },
  462. handleEdit(index, row)
  463. {
  464. this.title='编辑';
  465. this.form.id = row.id
  466. this.dialogFormVisible_edit = true;
  467. this.$request({
  468. params: {
  469. r:'mall/role/edit',
  470. id:row.id
  471. },
  472. }).then(e => {
  473. if(e.data.code==0){
  474. this.form.title = e.data.data.role.title;
  475. this.form.sort = e.data.data.role.sort;
  476. this.form.status = e.data.data.role.status;
  477. this.form.pid = e.data.data.role.pid;
  478. this.parent_title = e.data.data.parent_title;
  479. this.parent_list = e.data.data.list;
  480. this.tree_data2 = e.data.data.item_list2;
  481. this.tree_data3 = e.data.data.item_list3;
  482. this.checkedKey = e.data.data.checked_key;
  483. }
  484. }).catch(e => {
  485. });
  486. },
  487. postEdit(formName){
  488. this.$refs[formName].validate((valid) => {
  489. if(valid){
  490. // let item_ids = this.$refs.tree.getCheckedKeys();
  491. // let parent_item_ids = this.$refs.tree.getHalfCheckedKeys();
  492. // if(parent_item_ids.length!=0){
  493. // parent_item_ids.forEach(function (item) {
  494. // item_ids.push(item);
  495. // });
  496. // }
  497. let item_ids2 = this.$refs.tree2.getCheckedKeys();
  498. let item_ids3 = this.$refs.tree3.getCheckedKeys();
  499. let item_ids = [];
  500. item_ids2.forEach(function (item_id){
  501. item_ids.push(item_id);
  502. });
  503. item_ids3.forEach(function (item_id){
  504. item_ids.push(item_id);
  505. });
  506. this.form.item_ids.push = item_ids;
  507. this.$request({
  508. method:"post",
  509. params: {
  510. r:'mall/role/edit',
  511. },
  512. data:this.form
  513. }).then(e => {
  514. if(e.data.code==0){
  515. if(this.form.id){
  516. this.dialogFormVisible_edit = false;
  517. }else{
  518. this.dialogFormVisible_add = false;
  519. }
  520. this.$message({
  521. message: e.data.msg,
  522. type: 'success'
  523. });
  524. this.dialogFormVisible_edit = false;
  525. this.handleClose(formName);
  526. }else{
  527. this.$message.error(e.data.msg);
  528. }
  529. }).catch(e => {
  530. });
  531. }
  532. });
  533. },
  534. postAdd(formName){
  535. this.$refs[formName].validate((valid) => {
  536. if(valid){
  537. let item_ids2 = this.$refs.tree2.getCheckedKeys();
  538. let item_ids3 = this.$refs.tree3.getCheckedKeys();
  539. let item_ids = [];
  540. item_ids2.forEach(function (item_id){
  541. item_ids.push(item_id);
  542. });
  543. item_ids3.forEach(function (item_id){
  544. item_ids.push(item_id);
  545. });
  546. this.form.item_ids = item_ids;
  547. this.$request({
  548. method:"post",
  549. params: {
  550. r:'mall/role/edit',
  551. },
  552. data:this.form
  553. }).then(e => {
  554. if(e.data.code==0){
  555. this.dialogFormVisible_add = false;
  556. this.$message({
  557. message: e.data.msg,
  558. type: 'success'
  559. });
  560. this.dialogFormVisible_edit = false;
  561. this.handleClose(formName);
  562. }else{
  563. this.$message.error(e.data.msg);
  564. }
  565. }).catch(e => {
  566. });
  567. }
  568. });
  569. },
  570. handleDelete(index, row) {
  571. this.$confirm('删除该条数据后不可以恢复, 是否继续?', '警告', {type: 'warning'}).then(() => {
  572. this.form.id = row.id
  573. this.$request({
  574. params: {
  575. r: 'mall/role/del',
  576. id: row.id,
  577. },
  578. }).then(e => {
  579. if (e.data.code == 0) {
  580. this.$message({
  581. message: e.data.msg,
  582. type: 'success'
  583. });
  584. } else {
  585. this.$message({
  586. message: e.data.msg,
  587. type: 'error'
  588. });
  589. }
  590. }).catch(e => {
  591. });
  592. });
  593. },
  594. handleClose(formName){
  595. this.$refs[formName].resetFields();
  596. },
  597. handleClick(tab, event) {
  598. console.log(tab, event);
  599. }
  600. },
  601. });
  602. </script>