create.php 3.3 KB

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