permissions.blade.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <div style="margin-top: 10px;" id="roles-app">
  2. <div style="text-align: center;margin-top: 5px;margin-bottom: 10px;font-size: 20px;">
  3. 编辑 - 权限
  4. </div>
  5. <el-form action="{{route('admin.role.setPermission')}}" method="post" id="form-create">
  6. <!-- 链接 -->
  7. <el-row :gutter="20">
  8. <el-col :span="6" v-for="data in permission">
  9. <el-tree
  10. ref="tree"
  11. :data="data"
  12. show-checkbox
  13. node-key="id"
  14. :default-checked-keys="permissionIds"
  15. :default-expand-all="true"
  16. @check-change="handleCheckChange"
  17. :props="defaultProps">
  18. </el-tree>
  19. </el-col>
  20. </el-row>
  21. <input type="hidden" v-model="permissionIds" name="permission_ids"></input>
  22. <input type="hidden" value="{{$id}}" name="id"></input>
  23. <ui-submit></ui-submit>
  24. </el-form>
  25. </div>
  26. <script type="application/javascript">
  27. $(function () {
  28. // 注意:Vue组件一定放在jQuery.validator前面验证
  29. new Vue({
  30. el: '#roles-app',
  31. data: function () {
  32. return {
  33. permission:{!! json_encode($permission) !!},
  34. permissionIds:{!! json_encode($permission_ids) !!},
  35. defaultProps: {
  36. children: 'children',
  37. label: 'label'
  38. }
  39. };
  40. },
  41. methods:{
  42. handleCheckChange(data, checked, indeterminate) {
  43. let permissionIds=[];
  44. this.$refs.tree.forEach((v,k)=>{
  45. let selectKey=v.getCheckedKeys();
  46. if(selectKey.length>0){
  47. permissionIds.push(...selectKey)
  48. }
  49. })
  50. this.permissionIds=permissionIds;
  51. }
  52. }
  53. });
  54. jQuery.validator.setDefaults({
  55. debug: false, // 调试模式true不会提交,false允许提交
  56. success: "success", // 匹配成功的class样式名称
  57. errorElement: 'div' // 兼容el标签时使用(兼容el Vue组件label.error标签问题)
  58. });
  59. // 前台数据验证 验证需要设置window.form全局变量
  60. window.form = $('#form-create').validate({
  61. rules: {
  62. name: {
  63. required: true,
  64. maxlength: 200,
  65. normalizer: function (value) {
  66. return $.trim(value);
  67. }
  68. }
  69. }
  70. });
  71. // 编辑保存变量
  72. window.formDatum = $('form').serialize();
  73. });
  74. </script>
  75. @include('layouts.admin.form_script')