chengkun
2025-08-15 3411c9089d6c295b445979faa2b4009171e3896e
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
var menu_index = $('#menu_index').val();
//检查menulist变量是否定义
if (menu_list === undefined) {
    menu_list = [];
}
 
const sharedMixin = {
    data() {
        return {
            menu_index: menu_index,
            side_menu_collapse: false,
            default_aside_width: "250px",
            el_aside_width: "250px",
            side_menu_show_type: 1,/////左侧菜单收放状态,1=展开,2=收缩
            breadcrumbList: [],
            menuList: menu_list,///菜单列表
            url: '',
            currentLang: localStorage.getItem('lang') || 'zh-cn',
            langPag: {},// 存储加载后的语言包
            languageList: [
                { id: 1, name_loc: '简体中文', symbol: 'zh-cn' },
                { id: 2, name_loc: 'English', symbol: 'en-us' },
                { id: 3, name_loc: 'ar', symbol: 'ar' },
            ],
        }
    },
    mounted() {
        this.getLanguage();
        if (this.currentLang == 'en-us') {
            this.el_aside_width = this.default_aside_width = "270px"
        }
        else if (this.currentLang == 'zh-cn') {
            this.el_aside_width = this.default_aside_width = "250px";
        }
        else {
            this.el_aside_width = this.default_aside_width = "250px";
        }
    },
    created() {
        // this.sharedMethod()
        // console.log(this.$data.menu_index);
        this.loadLanguage();
        this.getMenu();
        //this.changeLang(this.currentLang, false);
    },
    methods: {
        getLanguage() {
            const that = this;
            const url = "/seller/login/getLanguage.html";
            postRequest(url, {}).then((res) => {
                if (res.data.code === 200) {
                    that.languageList = res.data.list
                }
            }).catch((error) => {
 
            });
        },
        // 异步加载语言包的方法
        async loadLanguage() {
            try {
                //获取默认语言
                let lang = localStorage.getItem('lang') || 'zh-cn';
                const response = await fetch(`/static/lang/1/${lang}.json`);
                this.langPag = await response.json();
            } catch (error) {
                // 回退到中文
                const zhResponse = await fetch('/static/lang/1/zh-cn.json');
                this.langPag = await zhResponse.json();
            }
        },
        // 切换语言
        async changeLang(lang, ifreload) {
            if (!['zh-cn', 'en-us', 'ar'].includes(lang)) {
                lang = 'zh-cn';
            }
            this.currentLang = lang;
            this.setLanguage(lang, ifreload);
            //await this.loadLanguage(lang, ifreload);
        },
        //重写消息弹窗方法,加入语言包
        dhknofity(code, msg) {
            if (code == '200') {
                this.$notify.success({
                    title: this.t('common.success', 'Success'),
                    message: this.t(msg),
                    position: "top-left"
                });
            } else {
                this.$notify.error({
                    title: this.t('common.error', 'Error'),
                    message: this.t(msg),
                    position: "top-left"
                });
            }
        },
        // 翻译方法
        t(key, value = '') {
            if (value == '') {
                value = key
            }
            return key.split('.').reduce((obj, k) => obj?.[k], this.langPag) || value;
        },
        setLanguage(lang, ifreload) {
            let url = "/seller/login/setLang.html"
            postRequest(url, { lang: lang }).then(res => {
                if (res.data.code == 200) {
                    localStorage.setItem('lang', lang);
                    window.location.reload();
                }
            });
        },
        sharedMethod() {
            // 共享的方法逻辑
            // console.log(1213213123123);
        },
 
        /////切换语言/////
        switchLanguage(type) {
            /////提交保存到数据库默认语言类型/////
 
            /////切换语言//////
            window.switchLanguage(type);
        },
 
        /////左侧菜单跳转/////
        goto_menu(url) {
            window.location.href = url;
        },
 
        /////左侧菜单收放状态
        show_side_menu() {
            if (this.side_menu_show_type == 1) {
                /////设置为收缩状态/////
                this.el_aside_width = "auto";
                this.side_menu_show_type = 2;
                this.side_menu_collapse = true;
            } else {
                /////设置为展开状态/////
                this.el_aside_width = this.default_aside_width;
                this.side_menu_show_type = 1;
                this.side_menu_collapse = false;
            }
        },
        getMenu() {
            //左侧菜单加载体验优化
            let that = this;
            if (this.menuList.length > 0) {
                this.url = new URL(window.location.href)
                let menus = this.getMenus(that.menuList)
                let home = [{ title: that.menuList[0].title, menu_url: '/seller/index/index.html' }]
                if (menus !== undefined) {
                    if (this.url.pathname !== '/seller/index/index.html' && this.url.href !== '/seller/index/index.html') {
                        menus = home.concat(menus)
                    }
                } else {
                    menus = home
                }
                this.breadcrumbList = menus
                return;
            }
            let url = "/seller/index/getMenu.html"
            postRequest(url, { menuindex: menu_index }).then(res => {
                console.log(res);
                if (res.data.code == 200) {
                    that.menuList = res.data.data;
                    that.menu_index = menu_index
                    this.url = new URL(window.location.href)
                    let menus = this.getMenus(that.menuList)
                    let home = [{ title: that.menuList[0].title, menu_url: '/seller/index/index.html' }]
                    if (menus !== undefined) {
                        if (this.url.pathname !== '/seller/index/index.html' && this.url.href !== '/seller/index/index.html') {
                            menus = home.concat(menus)
                        }
                    } else {
                        menus = home
                    }
                    this.breadcrumbList = menus
                    console.log(this.breadcrumbList)
                }
            });
        },
        getMenus(menuList, arr, z) {
            arr = arr || []
            z = z || 0
            for (let i = 0; i < menuList.length; i++) {
                let item = menuList[i]
                arr[z] = item
 
                if (menuList[i].menu_url != null && menuList[i].menu_url != '') {
                    if (this.url.pathname === menuList[i].menu_url || this.url.pathname.includes(menuList[i].menu_url.slice(0, -5))) {
                        return arr.slice(0, z + 1)
                    }
                }
 
                if (menuList[i].children && menuList[i].children.length) {
                    let res = this.getMenus(menuList[i].children, arr, z + 1)
                    if (res) {
                        return res
                    }
                }
            }
        },
 
        curentTime() {
            var now = new Date();
            var year = now.getFullYear();       // 年
            var month = now.getMonth() + 1;     // 月
            var day = now.getDate();            // 日
            var hh = now.getHours();            // 时
            var mm = now.getMinutes();          // 分
            var ss = now.getSeconds();          // 秒
            var clock = year + "-";
 
            if (month < 10)
                clock += "0";
            clock += month + "-";
            if (day < 10)
                clock += "0";
            clock += day + " ";
            if (hh < 10)
                clock += "0";
            clock += hh + ":";
            if (mm < 10)
                clock += "0";
            clock += mm + ":";
            if (ss < 10)
                clock += "0";
            clock += ss;
            return clock;
        },
 
        //获取表格中最后一列的宽度
        observeLastColumnWidth() {
            // 获取表格的 DOM 元素
            if (typeof this.$refs.tableRef == 'undefined') {
                return false;
            }
            try {
                const tableHeader = this.$refs.tableRef.$el.querySelector('.el-table__header-wrapper').querySelector('colgroup');
                if (tableHeader) {
                    // 获取最后一列的 DOM 元素
                    const lastColumn = tableHeader.querySelector('col:last-child');
                    if (lastColumn) {
                        // 创建 ResizeObserver 实例
                        const observer = new ResizeObserver((entries) => {
                            for (const entry of entries) {
                                const columnWidth = entry.contentRect.width; // 获取列宽
                                this.lastColumn = columnWidth;
                                // console.log(columnWidth);
                            }
                        });
                        // 监听最后一列的宽度变化
                        observer.observe(lastColumn);
                    }
                }
            }
            catch (error) {
                // console.log(error)
                return false;
            }
 
        },
        //设置最后一列的对齐方式
        alignValue(width) {
            // console.log(this.lastColumn, width);
            if (this.lastColumn > width) {
                return 'left';
            } else {
                return 'center';
            }
        },
    }
}