edit.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!DOCTYPE html>
  2. <!--suppress JSAnnotator -->
  3. <html lang="zh-CN">
  4. <head>
  5. {include file="public/head"}
  6. <title></title>
  7. </head>
  8. <body>
  9. <div id="form-add" class="mp-form" v-cloak="">
  10. <i-Form :model="formData" :label-width="80" >
  11. <Form-Item label="身份名称">
  12. <i-input v-model="formData.role_name" placeholder="请输入身份名称"></i-input>
  13. </Form-Item>
  14. <Form-Item label="是否开启">
  15. <Radio-Group v-model="formData.status">
  16. <Radio label="1">开启</Radio>
  17. <Radio label="0">关闭</Radio>
  18. </Radio-Group>
  19. </Form-Item>
  20. <Form-Item label="权限">
  21. <Tree :data="menus" show-checkbox ref="tree"></Tree>
  22. </Form-Item>
  23. <Form-Item :class="'add-submit-item'">
  24. <i-Button :type="'primary'" :html-type="'submit'" :size="'large'" :long="true" :loading="loading" @click.prevent="submit">提交</i-Button>
  25. </Form-Item>
  26. </i-Form>
  27. </div>
  28. <script>
  29. $eb = parent._mpApi;
  30. var role = <?php echo $role; ?> || {};
  31. var menus = <?php echo $menus; ?> || [];
  32. mpFrame.start(function(Vue){
  33. new Vue({
  34. el:'#form-add',
  35. data:{
  36. formData:{
  37. role_name:role.role_name || '',
  38. status:String(role.status) || '1',
  39. checked_menus:role.rules
  40. },
  41. menus:[],
  42. loading:false
  43. },
  44. methods:{
  45. tidyRes:function(){
  46. var data = [];
  47. menus.map((menu)=>{
  48. data.push(this.initMenu(menu));
  49. });
  50. this.$set(this,'menus',data);
  51. },
  52. initMenu:function(menu){
  53. var data = {},checkMenus = ','+this.formData.checked_menus+',';
  54. data.title = menu.menu_name;
  55. data.id = menu.id;
  56. if(menu.child && menu.child.length >0){
  57. data.children = [];
  58. menu.child.map((child)=>{
  59. data.children.push(this.initMenu(child));
  60. })
  61. }else{
  62. data.checked = checkMenus.indexOf(String(','+data.id+',')) !== -1;
  63. data.expand = !data.checked;
  64. }
  65. return data;
  66. },
  67. submit:function(){
  68. this.loading = true;
  69. this.formData.checked_menus = [];
  70. this.$refs.tree.getCheckedNodes().map((node)=>{
  71. this.formData.checked_menus.push(node.id);
  72. });
  73. $eb.axios.post("{$updateUrl}",this.formData).then((res)=>{
  74. if(res.status && res.data.code == 200)
  75. return Promise.resolve(res.data);
  76. else
  77. return Promise.reject(res.data.msg || '添加失败,请稍候再试!');
  78. }).then((res)=>{
  79. $eb.message('success',res.msg || '操作成功!');
  80. $eb.closeModalFrame(window.name);
  81. }).catch((err)=>{
  82. this.loading=false;
  83. $eb.message('error',err);
  84. });
  85. }
  86. },
  87. mounted:function(){
  88. t = this;
  89. this.tidyRes();
  90. }
  91. });
  92. });
  93. </script>
  94. </body>