Mr.Zhang
2023-09-11 586288a9e606ce224793e4888cca95e964819067
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<template>
  <GlobalWindow
    class="handle-table-dialog"
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <p class="tip" v-if="form.parentId != null && form.id == null">为 <em>{{parentName}}</em> 新建子菜单</p>
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="上级菜单" prop="parentId">
        <MenuSelect v-if="visible" v-model="form.parentId" placeholder="请选择上级菜单" type="2" :exclude-id="excludeMenuId" clearable :inline="false"/>
      </el-form-item>
      <el-form-item label="菜单名称" prop="name" required>
        <el-input v-model="form.name" placeholder="请输入菜单名称" v-trim maxlength="50"/>
      </el-form-item>
      <el-form-item label="h5访问路径" prop="path">
        <el-input v-model="form.path" placeholder="请输入访问路径" v-trim maxlength="200"/>
      </el-form-item>
      <el-form-item label="小程序访问路径" prop="pathSec">
        <el-input v-model="form.pathSec" placeholder="请输入访问路径" v-trim maxlength="200"/>
      </el-form-item>
      <el-form-item label="图标" prop="icon" class="form-item-icon">
        <div style="display: flex;">
          <UploadAvatarImage
            :file="{ 'imgurlfull': form.fullIcon, 'imgurl': form.icon }"
            :uploadData="uploadData"
            customStyle="width: 80px; height: 80px;"
            tipsLabel="上传图标"
            @uploadSuccess="uploadReverseSuccess"
            @uploadEnd="isUploading=false"
            @uploadBegin="isUploading=true"
          />
          <div style="display: flex; flex-direction: column-reverse;" v-if="!!form.icon">
            <el-button style="margin-left: 5px; padding: 0 5px;" type="text" @click="deletePic">删除</el-button>
          </div>
        </div>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input type="textarea" v-model="form.remark" placeholder="请输入菜单备注" v-trim :rows="3" maxlength="500"/>
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import MenuSelect from '@/components/common/MenuSelect'
import UploadAvatarImage from '@/components/common/UploadAvatarImage.vue'
import icons from '@/utils/icons'
export default {
  name: 'OperaMenuH5Window',
  extends: BaseOpera,
  components: { MenuSelect, GlobalWindow, UploadAvatarImage },
  data () {
    return {
      icons,
      isUploading: false,
      // 上级菜单名称
      parentName: '',
      // 需排除选择的菜单ID
      excludeMenuId: null,
      uploadData: {
        // floader: 'company/menu'
        folder: 'company/menu'
      },
      parent: {},
      // 表单数据
      form: {
        id: null,
        parentId: null,
        name: '',
        path: '',
        pathSec: '',
        icon: '',
        fullIcon: '',
        remark: '',
        type: '2'
      },
      // 验证规则
      rules: {
        name: [
          { required: true, message: '请输入菜单名称' }
        ]
      }
    }
  },
  
  created () {
    this.config({
      api: '/system/menu'
    })
  },
  methods: {
    /**
     * @title: 窗口标题
     * @target: 编辑的菜单对象
     * @parent: 新建时的上级菜单
     * @type: 0平台 1、企业 2、h5
     */
    open (title, target, parent) {
      debugger
      this.title = title
      
      this.visible = true
      // 新建,menu为空时表示新建菜单
      if (target == null) {
        this.excludeMenuId = null
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.parent = parent
          this.form.id = null
          this.form.parentId = parent == null ? null : parent.id
          this.parentName = parent == null ? null : parent.name
          this.form.fullIcon = ''
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        this.excludeMenuId = target.id
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        this.form.fullIcon = !!target.icon ? (target.resourcePath + target.icon) : ''
      })
    },
    uploadReverseSuccess(file) {
      this.form.icon = file.imgurl;
      this.form.fullIcon = file.imgurlfull;
    },
    deletePic() {
      this.form.fullIcon=''
      this.form.icon=''
    }
  },
}
</script>
 
<style scoped lang="scss">
@import "@/assets/style/variables";
$icon-background-color: $primary-color;
.global-window {
  .tip {
    margin-bottom: 12px;
    em {
      font-style: normal;
      color: $primary-color;
      font-weight: bold;
    }
  }
  // 图标
  ::v-deep .form-item-icon {
    .el-form-item__content {
      height: 193px;
      overflow-y: auto;
    }
    .el-radio-group {
      background: $icon-background-color;
      padding: 4px;
      .el-radio {
        margin-right: 0;
        color: #fff;
        padding: 6px;
        &.is-checked {
          background: $primary-color-sel;
          border-radius: 10px;
        }
        .el-radio__input.is-checked + .el-radio__label {
          color: #fff;
        }
      }
      .el-radio__input {
        display: none;
      }
      .el-radio__label {
        padding-left: 0;
        // element-ui图标
        i {
          font-size: 30px;
        }
        // 自定义图标
        [class^="eva-icon-"], [class*=" eva-icon-"] {
          width: 30px;
          height: 30px;
          background-size: 25px;
          vertical-align: bottom;
        }
      }
      .el-radio--small {
        height: auto;
        padding: 8px;
        margin-left: 0;
      }
    }
  }
}
</style>