edit.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. parent.$(".J_iframe:visible")[0].contentWindow.location.reload();
  82. }).catch((err)=>{
  83. this.loading=false;
  84. $eb.message('error',err);
  85. });
  86. }
  87. },
  88. mounted:function(){
  89. t = this;
  90. this.tidyRes();
  91. }
  92. });
  93. });
  94. </script>
  95. </body>