zhouwx
2024-11-12 1e2bd6710762860f1735baef0f61be1d8edb2fe2
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
<template>
    <div>
        <a-layout id="components-layout-demo-custom-trigger" :style="{ height: '100vh' }">
            <a-layout-sider v-model="collapsed" :trigger="null" collapsible>
        <div class="logo" v-if="!collapsed">{{ '预警响应系统' }}</div>
        <div class="logo" v-else><a-icon type="alert" /></div>
                <menuSider />
            </a-layout-sider>
            <a-layout>
                <a-layout-header style="background: #fff; padding: 0">
                    <a-icon class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'"
                        @click="() => (collapsed = !collapsed)"/>
                    <a-dropdown>
                        <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                            您好,{{userInfo.realName}} <a-icon type="down"/>
                        </a>
                        <a-menu slot="overlay">
                            <a-menu-item>
                                <a href="javascript:;" @click="editPwd">修改密码</a>
                            </a-menu-item>
                            <a-menu-item>
                                <a href="javascript:;" @click="backHome">回到首页</a>
                            </a-menu-item>
                            <a-menu-item>
                                <a @click="logout">退出登录</a>
                            </a-menu-item>
                        </a-menu>
                    </a-dropdown>
                </a-layout-header>
                <TabsHeader :pageList="pageList" :activePage="activePage" @change="changePage" @close="remove" />
                <a-layout-content :style="{
          margin: '15px 16px 24px 16px',
        }">
                    <!-- Content -->
          <keep-alive include="notice">
                      <router-view ref="tabContent"></router-view>
          </keep-alive>
                    <div style="height: 30px;text-align: center;line-height: 30px">
            技术支持:技术保障部
          </div>
                </a-layout-content>
            </a-layout>
 
        </a-layout>
    <pwd-mod ref="pwdMod"></pwd-mod>
<!--        <center style="textAlign: center;margin-left: 5%;margin-top:50px;">-->
<!--            技术支持:中国科学院-->
<!--        </center>-->
    </div>
</template>
 
<script>
    import menuSider from "@/layout/menuSider";
    import TabsHeader from '@/components/TabsHeader';
  import pwdMod from "@/views/Admin/components/pwdMod";
  import { loginOut, getDistrictInfo } from "@/api/login";
  import { Session, getUserInfo} from '@/util/storage';
  import Cookies from "js-cookie";
  import {getAreaWithUserIfo} from "@/api/user";
    export default {
        name: "Home",
        data() {
            return {
        userInfo: getUserInfo(),
                collapsed: false, //返回logo图片或表述
                pageList: [],
                activePage: '',
                multiPage: 24
            };
        },
        components: {
            menuSider,
            TabsHeader,
      pwdMod
        },
        created() {
            const route = this.$route
            if (this.pageList.findIndex(item => item.path === route.path) === -1) {
                this.pageList.push(this.createPage(route))
            }
            this.activePage = route.path
            if (this.multiPage) {
                this.$nextTick(() => {
                    this.setCachedKey(route)
                })
                this.addListener()
            }
      this.getAreaUsers(getUserInfo().districtId)
        },
        watch: {
            '$route': function(newRoute) {
                this.activePage = newRoute.path
                const page = this.pageList.find(item => item.path === newRoute.path)
                if (!this.multiPage) {
                    this.pageList = [this.createPage(newRoute)]
                } else if (page) {
                    page.fullPath = newRoute.fullPath
                } else if (!page) {
                    this.pageList.push(this.createPage(newRoute))
                }
                if (this.multiPage) {
                    this.$nextTick(() => {
                        this.setCachedKey(newRoute)
                    })
                }
            }
        },
        methods: {
      backHome(){
        this.$router.push('/home')
      },
 
      editPwd(){
        const t = this
        t.$refs.pwdMod.updateType = 1
        t.$refs.pwdMod.form.uid = t.userInfo.uid
        t.$refs.pwdMod.visible = true
      },
 
            logout(){
        const t = this
        this.$confirm({
          title: '提示',
          content: h => <div>该操作将登出,是否继续?</div>,
          cancelText: '取消',
          okText: '确认',
          centered: true,
          onOk() {
            loginOut().then(res=>{
              if (res.data.code === 100) {
                Session.clear(); // 清除缓存/token等
                // 使用 reload 时,不需要调用 resetRoute() 重置路由
                t.$router.push('/')
                // window.location.reload();
              } else {
                this.$message.warning(res.data.msg);
              }
            })
          },
          onCancel() {
            console.log('Cancel');
          },
          class: 'test',
        });
            },
 
      // async getDistrictInfo(){
      //   let res = await getDistrictInfo()
      //   if(res.data.code == 100){
      //     console.log(res.data.data)
      //     Cookies.set('district', res.data.data);
      //     console.log(Cookies.get('district'),666)
      //   } else {
      //     this.$message.warning(res.data.msg);
      //   }
      // },
 
            changePage(key) {
                this.activePage = key
                const page = this.pageList.find(item => item.path === key)
                this.$router.push(page.fullPath)
            },
            remove(key, next) {
                if (this.pageList.length === 1) {
                    return;
                }
                //清除缓存
                let index = this.pageList.findIndex(item => item.path === key)
                this.clearCaches = this.pageList.splice(index, 1).map(page => page.cachedKey)
                if (next) {
                    this.$router.push(next)
                } else if (key === this.activePage) {
                    index = index >= this.pageList.length ? this.pageList.length - 1 : index
                    this.activePage = this.pageList[index].path
                    this.$router.push(this.activePage)
                }
            },
            createPage(route) {
                return {
                    keyPath: route.matched[route.matched.length - 1].path,
                    fullPath: route.fullPath,
                    loading: false,
                    path: route.path,
                    title: route.meta && route.meta.title,
                    unclose: route.meta && route.meta.page && (route.meta.page.closable === false),
                }
            },
            /**
             * 设置页面缓存的key
             * @param route 页面对应的路由
             */
            setCachedKey(route) {
                const page = this.pageList.find(item => item.path === route.path)
                page.unclose = route.meta && route.meta.page && (route.meta.page.closable === false)
                if (!page._init_) {
                    const vnode = this.$refs.tabContent.$vnode
                    page.cachedKey = vnode.key + vnode.componentOptions.Ctor.cid
                    page._init_ = true
                }
            },
            /**
             * 添加监听器
             */
            addListener() {
                window.addEventListener('page:close', this.closePageListener)
            },
            /**
             * 移出监听器
             */
            removeListener() {
                window.removeEventListener('page:close', this.closePageListener)
            },
            closePageListener(event) {
                const {
                    closeRoute,
                    nextRoute
                } = event.detail
                const closePath = typeof closeRoute === 'string' ? closeRoute : closeRoute.path
                const path = closePath && closePath.split('?')[0]
                this.remove(path, nextRoute)
            },
      async getAreaUsers(districtId) {
        let t = this
        let res = await getAreaWithUserIfo()
        if (res.data.code == 100) {
          if (res.data.data) {
            t.userTitTree(res.data.data)
            const areaUsers = t.findNodeById(res.data.data, districtId).children
            localStorage.removeItem('areaUsers')
            localStorage.setItem('areaUsers',JSON.stringify(areaUsers))
          } else {
            console.log('暂无数据')
          }
        } else {
          this.$message.warning(res.data.msg);
        }
      },
 
      // 根据id查对象
      findNodeById(data, value) {
        for (const node of data) {
          if (node.id === value) {
            return node;
          }
          if (node.children) {
            const foundNode = this.findNodeById(node.children, value);
            if (foundNode) {
              return foundNode;
            }
          }
        }
        return null;
      },
 
      // 将树状数据name字段放入users的姓名电话
      userTitTree(treeData) {
        for (const node of treeData) {
          if (node.users) {
            node.users = node.users.filter(i => i.roleId == 3)
            node.users = node.users.map((i) => {
              return {
                ...i,
                unittype: node.type,
                districtId: node.id
              }
            })
            node.name = node.name + '(' + node.users.map(i => i.realName + ' ' + i.phone).join(',') + ')'
          }
          if (node.children) {
            this.userTitTree(node.children)
          }
        }
        return treeData
      }
        }
    };
</script>
 
<style lang="less" scoped>
    #components-layout-demo-custom-trigger .trigger {
        font-size: 18px;
        line-height: 64px;
        padding: 0 24px;
        cursor: pointer;
        transition: color 0.3s;
    }
 
    #components-layout-demo-custom-trigger .trigger:hover {
        color: #1890ff;
    }
 
    .logo {
        height: 36px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px;
        color: #faad14;
        text-align: center;
        line-height: 36px;
        font-size: 22px;
        text-shadow: 0 0 1px #000,
    }
 
    .ant-dropdown-link {
        float: right;
        margin-right: 25px;
    }
</style>