ZengTao
2024-11-01 7ac0936473cfa23ed0fcb3290d2d12fda1ba2411
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
<script setup>
import {Search} from "@element-plus/icons-vue";
import {reactive} from "vue";
import {useRouter} from "vue-router"
const router = useRouter()
const add = ref(false)
const adda = ref(false)
const addc = ref(false)
const addb = ref(false)
 
import { useI18n } from 'vue-i18n'
  const { t } = useI18n()
  let language = ref(localStorage.getItem('lang') || 'zh')
import request from "@/utils/request"
import { ref, onMounted } from "vue";
// import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
//  import LanguageMixin from './lang/LanguageMixin'
const selectedProjectNoa = ref(''); // 当前选中的角色 
// const options = ref<any[]>([]); // 下拉选项列表  
  const menuName = ref('');
  const listSort = ref('');
  const url = ref('');
const currentRow = reactive({}); // 当前行的数据 
const tableData = ref([])
const slot = ref('')
 request.get("/loadGlass/sys/menu/nav").then((res) => {
 if (res.code == 200) {
 console.log(res.data);
 tableData.value = res.data.tree
 } else {
 ElMessage.warning(res.msg)
 
 }
 });
const titleSelectJsona = ref({
  processType: [],
 
})
// const handleInputChangea = async (value: string) => {  
//   if (value) {  
//     await fetchOptionsa(value);  
//   } else {  
//     options.value = []; // 清空选项列表  
//   }  
// };  
onMounted(() => {  
  // 在组件挂载后调用 fetchOptions('') 来加载初始数据(如果需要)  
  fetchOptionsa('');  
}); 
  // 角色下拉选  
  const fetchOptionsa = async () => {  
  try {  
    // 发送请求到后端接口  
    const response = await request.post('/loadGlass/sys/role/queryRole',{
  key: ''
});  
    if (response.code === 200) {  
    titleSelectJsona.value.processTypea = response.data;
    console.log(response.data);
 
    } else {  
      ElMessage.warning(response.data);  
    }  
  } catch (error) {  
    console.error('Error fetching options:', error);  
  }  
}; 
const handleBindRack = (row) => {
  // selectedRow.value = row; // 更新选中的行数据  
  currentRow.menuName  = row.menuName; // 直接设置响应式属性  
  currentRow.id  = row.id; // 直接设置响应式属性  
  // currentRow.slot = row.slot;  
  // window.localStorage.setItem('deviceId', row.deviceId)
  // window.localStorage.setItem('slot', row.slot)
  addb.value = true; // 打开绑定架子对话框
};
function closeDialog(row) {
     add.value = false;
       menuName.value = '';
       listSort.value = '';
       url.value = '';
}
function closeDialoga(row) {
     adda.value = false;
       menuName.value = '';
       listSort.value = '';
       url.value = '';
}
function closeDialogb(row) {
     addb.value = false;
       menuName.value = '';
       listSort.value = '';
       url.value = '';
}
function closeDialogc(row) {
     addc.value = false;
       menuName.value = '';
       listSort.value = '';
       url.value = '';
}
// 添加一级菜单
const getTableRow = async () => {
  try {
    const response = await request.post('/loadGlass/sys/menu/save', {
      menuName: menuName.value,
      listSort: listSort.value,
      url: url.value,
    }); 
 
    if (response.code === 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      add.value = false;
     tableData.value = response.data;
       menuName.value = '';
       listSort.value = '';
       url.value = '';
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.msg);
    }
  } catch (error) {
    // 处理错误
    console.error(error);
  }
};
// 添加二级菜单
const getTableRowb = async () => {
  try {
    const dataToSend = {  
      parentId: currentRow.id,
      // menuName: currentRow.menuName,
      // children: [  
      //   {  
      menuName: menuName.value,
      listSort: listSort.value,
      url: url.value,
      //   }  
      // ]  
    };
    const response = await request.post('/loadGlass/sys/menu/save',dataToSend ); 
    if (response.code === 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      addb.value = false;
     tableData.value = response.data;
       menuName.value = '';
       listSort.value = '';
       url.value = '';
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.msg);
    }
  } catch (error) {
    // 处理错误
    console.error(error);
  }
};
// 处理编辑按钮点击  
function handleEdit(row) {  
  listSort.value = row.listSort; 
  menuName.value = row.menuName; 
  url.value = row.url; 
  adda.value = true; // 显示对话框  
}  
// 修改二级菜单
function handleEditc(row) {  
  listSort.value = row.listSort; 
  menuName.value = row.menuName; 
  url.value = row.url; 
  addc.value = true; // 显示对话框  
}  
// 编辑
const getTableRowa = async () => {
  try {
    const response = await request.post('/loadGlass/sys/menu/updateMenu', {
      parentId: currentRow.id,
      menuName: menuName.value,
      listSort: listSort.value,
      url: url.value,
    }); 
    if (response.code === 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      adda.value = false;
     tableData.value = response.data;
       menuName.value = '';
       listSort.value = '';
       url.value = '';
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.msg);
    }
  } catch (error) {
    // 处理错误
    console.error(error);
  }
}; 
// 编辑二级菜单
const getTableRowac = async () => {
  try {
    const response = await request.post('/loadGlass/sys/menu/updateMenu', {
      menuName: menuName.value,
      listSort: listSort.value,
      url: url.value,
    }); 
    if (response.code === 200) {
      // 绑定成功,处理逻辑
      ElMessage.success(response.message);
      addc.value = false;
     tableData.value = response.data;
       menuName.value = '';
       listSort.value = '';
       url.value = '';
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.msg);
    }
  } catch (error) {
    // 处理错误
    console.error(error);
  }
};
// 删除 
 const opena = async(row) => {  
  try {
    const confirmResult = await ElMessageBox.confirm(  
      t('customer.demenu'), 
      t('customer.prompt'),  
      {  
        confirmButtonText: t('customer.yes'), 
        cancelButtonText: t('customer.cancel'),
        type: 'warning',  
      } 
    );
    if (confirmResult === 'confirm') {  
      // 用户点击了“是”,现在调用删除接口  
      const response = await request.post("/loadGlass/sys/menu/deleteMenu", {
        menuId: row.id,
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
      } else {  
        // 删除失败,您可以处理错误或显示错误信息给用户  
      ElMessage.error(response.msg);
        // alert('删除失败:' + deleteResponse.message); 
      }  
    }  
  } catch (error) {  
    // 处理可能出现的错误,比如 ElMessageBox 抛出的异常等  
    console.error('发生错误:', error);  
  }  
};   
 
</script>
 
<template>
  <div style="height: 600px;">
     <el-button type="primary" style="margin-top: 10px;margin-left: 10px;"  size="mini" id="searchButton" @click="add = true">{{ $t('customer.addmenu') }}</el-button>
    <el-card style="flex: 1;margin-left: 10px;margin-top: 20px;" v-loading="loading">
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;max-height: 650px;">
              <el-table  
          :data="tableData" 
          height="550"
          @expand-change="handleExpandChange"  
          row-key="id" 
          :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}" 
        >  
          <el-table-column type="expand">  
            <template #default="props">  
              <div v-if="props.row.children && props.row.children.length">  
                <el-table  
                  :data="props.row.children"  
                  border
                  style="width: 100%;margin-left: 120px;"  
                  row-key="id"  
                  :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}" 
                >  
                  <el-table-column prop="menuName" :label="$t('customer.semenu')" align="center" min-width="140" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}"/>  
                  <el-table-column prop="url" :label="$t('customer.link')" align="center" min-width="160"/>  
          <el-table-column prop="listSort" align="center" :label="$t('customer.sort')" min-width="140"/>
                  <el-table-column fixed="right" :label="$t('customer.operate')" align="center">
            <template #default="scope">
              <el-button size="mini" type="text" plain @click="handleEditc(scope.row)">{{ $t('customer.exit') }}</el-button>
              <el-button size="mini" type="text" plain @click="opena(scope.row)">{{ $t('customer.delete') }}</el-button>
            </template>
        </el-table-column>
                </el-table>  
              </div>  
            </template>  
          </el-table-column>  
          <el-table-column prop="menuName" :label="$t('customer.firstmenu')" align="center" min-width="120"  />  
                  <el-table-column prop="url" :label="$t('customer.link')" align="center" min-width="200"/>  
          <el-table-column prop="listSort" align="center" :label="$t('customer.sort')" min-width="180" />
          <el-table-column fixed="right" :label="$t('customer.operate')" align="center" width="200">
            <template #default="scope">
              <el-button size="mini" type="text" plain @click="handleBindRack(scope.row)">{{ $t('customer.addmenua') }}</el-button>
              <el-button size="mini" type="text" plain @click="handleEdit(scope.row)">{{ $t('customer.exit') }}</el-button>
              <el-button size="mini" type="text" plain @click="opena(scope.row)">{{ $t('customer.delete') }}</el-button>
            </template>
        </el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
  <el-dialog v-model="add" top="23vh" width="37%" :title="$t('customer.addmenu')">
    <div style="margin-left: -50px;margin-top: 10px;margin-bottom: 10px;">
            <el-form  size="mini" label-width="150px">
      <el-form label-width="150px" label-position="right">
        <el-row style="margin-top: -15px;margin-bottom: -2px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div> 
          <el-form-item :label="$t('customer.firstmenuname')" :required="true" style="width: 25vw">
                <el-input v-model="menuName" autocomplete="off" :placeholder="$t('customer.inmenu')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        <el-row style="margin-top: 10px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div>
          <el-form-item :label="$t('customer.linka')" :required="true" style="width: 25vw">
                <el-input v-model="url" autocomplete="off" :placeholder="$t('customer.inlink')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        <el-row style="margin-top: 10px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div>
          <el-form-item :label="$t('customer.sorta')" :required="true" style="width: 25vw">
                <el-input v-model="listSort" autocomplete="off" :placeholder="$t('customer.insort')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        </el-form>
            </el-form>
          </div>
    <template #footer>
      <div id="dialog-footer">
        <el-button type="primary" @click="getTableRow">
          {{ $t('customer.sure') }}
        </el-button>
        <el-button @click="closeDialog">{{ $t('customer.cancel') }}</el-button>
      </div>
    </template>
  </el-dialog> 
  <el-dialog v-model="addb" top="23vh" width="37%" :title="$t('customer.addmenua')">
    <div style="margin-bottom: 20px">
      <el-form>
        <el-row style="margin-top: -15px;margin-bottom: -2px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
              <el-form-item :label="$t('customer.firstmenuname')"  style="width: 22vw">
                <!-- {{ currentRow.menuName }} -->
            <el-input disabled v-model="currentRow.menuName" autocomplete="off"></el-input>
              </el-form-item>
              </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div style="margin-left: -50px;margin-top: 10px;margin-bottom: 10px;">
            <el-form  size="mini" label-width="150px">
      <el-form label-width="150px" label-position="right">
        <el-row style="margin-top: -15px;margin-bottom: -2px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div> 
          <el-form-item :label="$t('customer.semenuname')" :required="true" style="width: 25vw">
                <el-input v-model="menuName" autocomplete="off" :placeholder="$t('customer.inmenu')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        <el-row style="margin-top: 10px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div>
          <el-form-item :label="$t('customer.linka')" :required="true" style="width: 25vw">
                <el-input v-model="url" autocomplete="off" :placeholder="$t('customer.inlink')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        <el-row style="margin-top: 10px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div>
          <el-form-item :label="$t('customer.sorta')" :required="true" style="width: 25vw">
                <el-input v-model="listSort" autocomplete="off" :placeholder="$t('customer.insort')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        </el-form>
            </el-form>
          </div>
    <template #footer>
      <div id="dialog-footer">
        <el-button type="primary" @click="getTableRowb">
          {{ $t('customer.sure') }}
        </el-button>
        <el-button @click="closeDialogb">{{ $t('customer.cancel') }}</el-button>
      </div>
    </template>
  </el-dialog> 
  <el-dialog v-model="adda" top="23vh" width="37%" :title="$t('customer.exmene')">
    <div style="margin-left: -50px;margin-top: 10px;margin-bottom: 10px;">
     <el-form ref="formRef" size="mini" label-width="150px">
      <el-form label-width="100px" label-position="right">
        <el-row style="margin-top: -15px;margin-bottom: -2px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div> 
          <el-form-item :label="$t('customer.menu')" :required="true" style="width: 25vw">
                <el-input v-model="menuName" autocomplete="off" :placeholder="$t('customer.inmenu')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        <el-row style="margin-top: 10px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div>
          <el-form-item :label="$t('customer.linka')" :required="true" style="width: 25vw">
                <el-input v-model="url" autocomplete="off" :placeholder="$t('customer.inlink')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        <el-row style="margin-top: 10px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div>
          <el-form-item :label="$t('customer.sorta')" :required="true" style="width: 25vw">
                <el-input v-model="listSort" autocomplete="off" :placeholder="$t('customer.insort')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        </el-form>
            </el-form>
          </div>
    <template #footer>
      <div id="dialog-footer">
        <el-button type="primary" @click="getTableRowa">
          {{ $t('customer.sure') }}
        </el-button>
        <el-button @click="closeDialoga">{{ $t('customer.cancel') }}</el-button>
      </div>
    </template>
  </el-dialog> 
  <el-dialog v-model="addc" top="23vh" width="37%" :title="$t('customer.exmenea')">
    <div style="margin-left: -50px;margin-top: 10px;margin-bottom: 10px;">
     <el-form ref="formRef" size="mini" label-width="150px">
      <el-form label-width="100px" label-position="right">
        <el-row style="margin-top: -15px;margin-bottom: -2px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div> 
          <el-form-item :label="$t('customer.menu')" :required="true" style="width: 25vw">
                <el-input v-model="menuName" autocomplete="off" :placeholder="$t('customer.inmenu')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        <el-row style="margin-top: 10px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div>
          <el-form-item :label="$t('customer.linka')" :required="true" style="width: 25vw">
                <el-input v-model="url" autocomplete="off" :placeholder="$t('customer.inlink')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        <el-row style="margin-top: 10px;">
          <el-col :span="6">
              <div id="dt" style="font-size: 15px;">
        <div>
          <el-form-item :label="$t('customer.sorta')" :required="true" style="width: 25vw">
                <el-input v-model="listSort" autocomplete="off" :placeholder="$t('customer.insort')"/>
              </el-form-item></div></div>
          </el-col>
        </el-row>
        </el-form>
            </el-form>
          </div>
    <template #footer>
      <div id="dialog-footer">
        <el-button type="primary" @click="getTableRowac">
          {{ $t('customer.sure') }}
        </el-button>
        <el-button @click="closeDialogc">{{ $t('customer.cancel') }}</el-button>
      </div>
    </template>
  </el-dialog> 
</template>
 
<style scoped>
 
#dt { display:block; float:left;line-height: 20px;margin-left: 100px;}
#dta { display:block; float:left;line-height: 20px;margin-left: 80%;}
#dialog-footer{
  text-align: center;
  margin-top: -15px;
}
#message{
  text-align: center;
  align-items: center;
  color: black;
   width: 200px;
   height: 100px;
   background-color: #337ecc;
   margin-left: 28%;
}
#awatch{
  height: 460px;
  /* margin-top: -60px; */
}
</style>