quanyawei
2024-08-28 247dacca9784396eeaf17ef3e85c7ae646b786e4
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<template>
<div>
  <a-card :bordered="false" style="margin-top: 24px">
    <table style="background-color: #FAFAFA;width: 100%;position: absolute;right: 50px">
      <tr style="background-color: #FAFAFA;height: 50px;width: 100%;height: 24px;margin-top: -25px;margin-left: 50px; left: 0;right: 0;;position: absolute;display: flex">
        <th style="position: relative;flex: 1;text-align: center">名称</th>
        <th style="position: relative;flex: 1;text-align: center">顺序</th>
        <th style="position: relative;flex: 1;text-align: center">路径</th>
        <th style="position: relative;flex: 1;text-align: center">操作</th>
      </tr>
    </table>
    <menu-list
            :menuListData="JSON.parse(JSON.stringify(webMenusData))"
    ></menu-list>
    <a-modal width="45%"  title="新增-菜单" destroyOnClose :visible="addModelFlag" @ok="saveMenuData"  @cancel="addModalCancel">
 
        <!---->
        <a-form-model style="margin-top: 8px"  ref="addMenuForm"
                    :label-col="{span: 4}"
                    :rules="rules"
                    :wrapper-col="{span: 14}"
                    :model="addForm">
        <a-row>
          <a-col :md="12" :sm="24">
            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="名称"  prop="name">
              <a-input placeholder="名称" v-model="addForm.name" />
            </a-form-model-item>
          </a-col>
<!--          <a-col v-if="addForm.parentId === -1" :md="12" :sm="24">-->
<!--            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="父菜单"  prop="name">-->
<!--              <a-input placeholder="父菜单" v-model="addForm.name" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :md="12" :sm="24">
            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="排序"  prop="order">
              <a-input placeholder="排序" v-model="addForm.order" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="路径"  prop="url">
              <a-input placeholder="路径" v-model="addForm.url" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-modal>
    <a-modal width="45%"  title="新增-根菜单" destroyOnClose :visible="addRootMenuModel" @ok="saveMenuData"  @cancel="addModalCancel">
 
      <!---->
      <a-form-model style="margin-top: 8px"  ref="addMenuForm"
                    :label-col="{span: 4}"
                    :wrapper-col="{span: 14}"
                    :rules="rules"
                    :model="addForm">
        <a-row>
          <a-col :md="12" :sm="24">
            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="名称"  prop="name">
              <a-input placeholder="名称" v-model="addForm.name" />
            </a-form-model-item>
          </a-col>
          <!--          <a-col v-if="addForm.parentId === -1" :md="12" :sm="24">-->
          <!--            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="父菜单"  prop="name">-->
          <!--              <a-input placeholder="父菜单" v-model="addForm.name" />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :md="12" :sm="24">
            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="排序"  prop="order">
              <a-input placeholder="排序" v-model="addForm.order" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="路径"  prop="url">
              <a-input placeholder="路径" v-model="addForm.url" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-modal>
    <a-modal width="45%"  title="编辑-菜单" destroyOnClose :visible="editModelFlag" @ok="editMenuData"  @cancel="editModalCancel">
 
      <!---->
      <a-form-model style="margin-top: 8px"  ref="editMenuForm"
                    :label-col="{span: 4}"
                    :wrapper-col="{span: 14}"
                    :rules="editRules"
                    :model="editForm">
        <a-row>
          <a-col :md="12" :sm="24">
            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="名称"  prop="name">
              <a-input placeholder="名称" v-model="editForm.name" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-model-item  :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="父菜单" v-if="rootFlag">
              <a-select
                      show-search
                      v-model="editForm.selectData.value"
                      option-filter-prop="children"
                      :filter-option="filterOption"
                      @change="handleChange">
<!--                       @blur="handleBlur"-->
              <a-select-option v-for="(item,index) of editForm.selectData.pMenuList" :key="item.id" > {{item.name}}</a-select-option>
            </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="排序"  prop="order">
              <a-input placeholder="排序" v-model="editForm.order" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-model-item :labelCol="{ span: 5 }" :wrapperCol="{ span: 15 }" label="路径">
              <a-input placeholder="路径" v-model="editForm.url" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-modal>
    <div class="tableListOperator2">
      <a-button icon="plus" type="primary" @click="() => this.addRootMenu()">
        新建根菜单
      </a-button>
    </div>
  </a-card>
</div>
 
 
</template>
 
<script lang="tsx">
  import {Component, Prop, Vue, Watch} from 'vue-property-decorator';
  import { get, post } from "@/util/request";
  import menuList from '@/components/webMenu/menuList.vue'
  import Bus from '@/bus'
  import logger from "vuex/types/logger";
  @Component({
      components:{
          menuList
      }
  })
  export default class WebMenu extends Vue{
      private text: any = 'alalallalaa'
      private webMenusData:any[] = []
      private addModel: boolean = false
      private rootMenuFlag: boolean = false
      // 添加双向绑定数据
      private addForm: any = {
          name: '',
          order: '',
          url: ''
      }
      // 修改双向绑定数据
      private editForm: any = {
          name: '',
          selectData: {
              pMenuList:null,//菜单下拉数据列表
              value:'',//选择下拉列表中选项后的值
              getlistLoading:false,//获取到下拉列表的数据前默认改选择器不可用
          },
          order: '',
          url: '',
          id: ''
      }
      private rules: any = {
          name:[
              { required: true, message: '名称不能为空' }
          ],
          order:[
              { required: true, message: '请输入序号' },
              { pattern:/^\+?[1-9][0-9]*|[0]$/, message: '请输入数字' }
          ]
      }
      private editRules: any = {
        name:[
          { required: true, message: '名称不能为空' }
        ],
        order:[
          { required: true, message: '请输入序号' },
          { pattern:/^\+?[1-9][0-9]*|[0]$/, message: '请输入数字' }
        ],
        rootFlag: [
 
        ]
 
      }
      // @Watch('addModel')
      // private addModelFlagWatch(newVal:string,oldVal:string) {
      // }
      get addModelFlag() {
          this.addModel =  this.$store.state.webMenu.webMenuAddFlag
          return this.addModel
      }
 
      get addRootMenuModel() {
          return this.rootMenuFlag
      }
      // 新增根菜单
      private addRootMenu() {
        this.$store.state.webMenu.webMenuParentId = 0
          this.rootMenuFlag = true
      }
      get editModelFlag() {
          return this.$store.state.webMenu.editModelFlag
      }
 
      private rFlag: boolean = true
      get rootFlag() {
          return this.rFlag
      }
 
      private editBeforeData:any = null
      private mounted() {
          this.getMenus()
          // 用于爷爷孙子组件传值
          Bus.$on( 'delete', (res: boolean) => {
              if (res) {
                  this.getMenus()
              }
          })
          Bus.$on( 'edit', (res: any) => {
              this.editBeforeData = res
              this.editForm.name = res.name
              this.editForm.order = res.order
              this.editForm.url = res.url
              this.editForm.selectData.value = res.parentId
              if ( this.editForm.selectData.value === 0 ) {
                  this.rFlag = false
              }else {
                  this.rFlag = true
              }
              this.editForm.id = res.id
              this.getAllMenuName()
          })
      }
 
      // 保存修改
      private editMenuData() {
        this.$refs.editMenuForm.validate((valid: any) => {
          if (valid){
            if (!(this.editBeforeData.order === this.editForm.order && this.editBeforeData.id === this.editForm.id
                && this.editBeforeData.name === this.editForm.name && this.editBeforeData.url === this.editForm.url
                && this.editBeforeData.parentId === this.editForm.selectData.value)) {
              post('menu/update', {
                    id: this.editForm.id,
                    name: this.editForm.name,
                    parentId: this.editForm.selectData.value,
                    order: this.editForm.order,
                    url: this.editForm.url
                  }).then((res: any) => {
                if (res.data.code === 0) {
                  this.getMenus()
                  this.$message.success(res.data.message)
                  this.$store.state.webMenu.editModelFlag = false
                }else {
                  this.$message.warning(res.data.message)
                }
              })
            }else {
              this.$message.warning('未修改')
            }
          }
        })}
      // 取消修改
      private editModalCancel() {
          this.$store.state.webMenu.editModelFlag = false
      }
 
      // 新增保存
      private saveMenuData() {
        this.$refs.addMenuForm.validate((valid: any) => {
          if (valid){
            post('menu/insert',
                {
                  name: this.addForm.name,
                  parentId: this.$store.state.webMenu.webMenuParentId,
                  order: this.addForm.order,
                  url: this.addForm.url
                }
            ).then((res: any) => {
              if (res.data.code === 0) {
                this.getMenus()
                this.addForm = {
                  name: '',
                  order: '',
                  url: ''
                }
                this.$message.success(res.data.message)
                this.$store.state.webMenu.webMenuAddFlag = false
                this.rootMenuFlag = false
              }else {
                this.$message.warning(res.data.message)
              }
            })
          }else {
 
          }
 
 
        })
 
 
      }
      // 取消新增
      private addModalCancel(){
          this.addModel = false
          this.$store.state.webMenu.webMenuAddFlag = false
          this.rootMenuFlag = false
      }
      private getMenus() {
          get('menu/query',{}).then((res: any) => {
            this.webMenusData = res.data.data.menus
          })
 
      }
 
 
      private  handleChange(value: any){
          this.editForm.selectData.value = value!=null && value !='' ? value : [];
      }
 
      private filterOption(input: any, option: any) {
          return (
              option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
          );
      }
      private getAllMenuName() {
          get("menu/queryNames",{
                  id: this.editForm.id
          }).then(res => {
            this.editForm.selectData.pMenuList = res.data.data.menuVOs
          })
      }
  }
</script>
 
<style lang="less">
 
 
  .tableListOperator2 {
    margin-bottom: 16px;
    margin-right: 50px;
    button {
      margin-left: 93%;
      margin-top: 10px;
    }
  }
</style>