cuiqian2004
8 天以前 f57571f987f3d25730123f488fccdfa3158ec5b1
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
<template>
    <view class="pages-index">
        <view class="login-content tems-cente">
            <view>
                <image :src="imgHttp" class="login-image" mode="widthFix"></image>
            </view>
            <view class="gungho-title"><text>{{ titleName}}</text>
            </view>
            <view class="gungho-tip"> <text>{{tip}}</text>
            </view>
        </view>
    </view>
</template>
 
<script>
    import Session from "@/common/utils.js"
    import {
        showModal,
        showToast,
        showLoading,
        hideLoading
    } from "@/common/Page.js"
    import {
        login,
        loginSession,
        loginDingTalk,
        loginWeChat
    } from "@/api/org.js"
    import {
        getDingAutoLoginInfo,
        autoLoginDing,
        autoLoginFeiShu,
        autoLoginWxQy,
    } from "@/api/index.js"
    export default {
        data() {
            return {
                titleName: getApp().globalData.loginTitleName || "工作任务管理平台",
                imgHttp: "",
                tip: '正在跳转...',
                options: {}
            }
        },
        onLoad(option) {
        
            this.options =option
            // #ifdef MP-DINGTALK
            
            my.setNavigationBar({
                backgroundColor: "#007AFF",
                frontColor: "#ffffff"
            })
            // #endif
            // {
            //     page_type: "prjevent_detail",
            //     id: "{86CE4507-FC29-4AD8-9A9F-779ADBE00F72}"
            // }//option
            this.loadData()
        },
        methods: {
            loadData() {
                const _this = this
                const app = getApp()
                uni.setNavigationBarTitle({
                    title: app.globalData.titleName
                })
                const apiPort = Session.getValue('apiport');
                app.globalData.files_flag = Session.getValue('files_flag');
                const portObj = app.globalData.apiport
                app.globalData.apiurl = {
                    org: `${app.globalData.httproot}:${apiPort?.org|| portObj?.org || 5101}`,
                    mobox: `${app.globalData.httproot}:${apiPort?.mobox || portObj?.mobox|| 5102}`,
                    data: `${app.globalData.httproot}:${apiPort?.data || portObj?.data|| 5103}`,
                    workflow: `${app.globalData.httproot}:${apiPort?.workflow || portObj?.workflow|| 5104}`,
                    gungho: `${app.globalData.httproot}:${apiPort?.gungho|| portObj?.gungho || 5109}`,
                }
                let loginInfo = Session.getValue('logininfo')
                if (loginInfo) {
                    if (loginInfo.sessionid) {
                        let userData = Session.getValue('userdata')
                        _this.checkSession(userData.user_login, loginInfo.sessionid, (res) => {
                            if (loginInfo.mobile) {
                                app.globalData.isPwdLogin = false
                            } else
                                app.globalData.isPwdLogin = true
                            _this.loginSuccess(loginInfo, res)
                        }, () => {
                            _this.login(loginInfo)
                        })
                    } else {
                        _this.login(loginInfo)
                    }
                }
            },
            login(loginInfo) {
                const _this = this
                const app = getApp()
                
                //#ifdef MP-WEIXIN || MP-LARK  ||  MP-DINGTALK
                if (loginInfo.mobile) {
                    _this.checkMobile(loginInfo.userlogin, loginInfo.mobile, (res) => {
                        app.globalData.isPwdLogin = false
                        _this.loginSuccess(loginInfo, res)
                    }, () => {
                        _this.autoLogin()
                    })
                }
                else
                {
                    _this.autoLogin()
                }
                // #endif
                //#ifndef MP-WEIXIN || MP-LARK || MP-DINGTALK
                uni.reLaunch({
                    url: '/pages/loading/loading'
                })
                // #endif
 
            },
            async autoLogin() {
                try {
                    const _this = this
                    showLoading("登录中,请稍后...")
                    var res = undefined
                    //#ifdef MP-WEIXIN
                    res = await autoLoginWxQy()
                    // #endif
                    //#ifdef MP-LARK
                    res = await autoLoginFeiShu()
                    // #endif
                    //#ifdef MP-DINGTALK
                    res = await autoLoginDing()
                    // #endif
                    if (!res) {
                        uni.reLaunch({
                            url: '/pages/loading/loading'
                        })
                    }
                    const app = getApp()
                    let loginInfo = {
                        userlogin: res.user_id,
                        username: res.user_name,
                        mobile: res.mobile,
                        password: "",
                        sessionid: res.session_id
                    }
                    app.globalData.isPwdLogin = false
                    _this.loginSuccess(loginInfo, res)
                    hideLoading()
 
                } catch (ex) {
                    hideLoading()
                    console.log(ex)
                    this.showError(ex)
                    uni.reLaunch({
                        url: '/pages/loading/loading'
                    })
                }
 
            },
 
            async checkMobile(account, mobile, callbackSucc, callbackFail) {
                try {
                    if (account && mobile) {
                        showLoading("登录中,请稍后...")
                        // #ifdef  MP-DINGTALK
                        let res = await loginDingTalk(account, mobile)
                        res.user_id = account
                        res.mobile = mobile
                        hideLoading()
                        if (typeof callbackSucc == 'function')
                            callbackSucc(res)
                        // #endif
                        //#ifdef MP-LARK  || MP-WEIXIN
                        let res = await loginWeChat(account, mobile)
                        res.user_id = account
                        res.mobile = mobile
                        hideLoading()
                        if (typeof callbackSucc == 'function')
                            callbackSucc(res)
                        // #endif    
                        //#ifndef MP-WEIXIN || MP-LARK || MP-DINGTALK
                        hideLoading()
                        if (typeof callbackFail == 'function')
                            callbackFail()
                        
                        // #endif
 
                    } else {
                        if (typeof callbackFail == 'function')
                            callbackFail()
                    }
                } catch (ex) {
                    hideLoading()
                    console.log("checkMobile", ex)
                    if (typeof callbackFail == 'function')
                        callbackFail()
                }
 
            },
 
            async checkSession(account, sessionID, callbackSucc, callbackFail) {
                try {
                    if (sessionID && account) {
                        showLoading("登录中,请稍后...")
                        const res = await loginSession(account, sessionID)
                        res.session_id = sessionID
                        hideLoading()
                        if (typeof callbackSucc == 'function')
                            callbackSucc(res)
                    } else {
                        if (typeof callbackFail == 'function')
                            callbackFail()
                    }
                } catch (ex) {
                    hideLoading()
                    console.log("checkSession", ex)
                    if (typeof callbackFail == 'function')
                        callbackFail()
                }
 
            },
            loginSuccess(loginInfo, userData) {
                console.log("loginSuccess", loginInfo)
                const app = getApp()
                Session.setValue('logininfo', loginInfo)
                userData.logintime = new Date().toDateString();
                app.globalData.userdata = userData;
                Session.setValue('userdata', userData);
                if (userData.files_info && !app.globalData.files_flag) {
                    if (userData.files_info.flag) {
                        app.globalData.files_flag = userData.files_info.flag
 
                    }
                }
                if (this.options.page_type == "prjevent_detail") {
                    uni.reLaunch({
                        url: '/pages/project/event/detail?eventId=' + this.options.id
                    })
                } else if (this.options.page_type == "prjevent_list") {
                    uni.reLaunch({
                        url: '/pages/project/event/index'
                    })
                } else if (this.options.page_type == "prjevent_create") {
                    uni.reLaunch({
                        url: '/pages/project/event/create'
                    })
                } else if (this.options.page_type == "task_detail") {
                    uni.reLaunch({
                        url: '/pages/task/detail?taskId=' + this.options.id
                    })
                } else if (this.options.page_type == "task_list") {
                    uni.reLaunch({
                        url: '/pages/task/index'
                    })
                } else if (this.options.page_type == "task_create") {
                    uni.reLaunch({
                        url: '/pages/task/create'
                    })
                } else {
                    uni.reLaunch({
                        url: '/pages/task/index'
                    })
                }
            },
            showError(ex) {
                let tip = typeof ex == 'string' ? ex : typeof ex.err_msg == 'string' ? ex.err_msg : typeof ex.errMsg ==
                    'string' ? ex.errMsg : ""
                showModal(tip, "提示", false)
            },
        }
    }
</script>
 
<style lang="less">
    .pages-index {
 
        display: flex;
        width: 750rpx;
        height: 100vh;
 
        .items-center {
            align-items: center
        }
 
        .login-content {
            width: 750rpx;
            height: 400px;
        }
 
        .login-image {
            display: block;
            margin: auto;
            height: 80px !important;
            width: 80px;
        }
 
        .gungho-title {
            font-size: 20px;
            font-weight: 300;
            margin: 24px 12px 12px;
            text-align: center;
        }
 
        .gungho-tip {
            font-size: 20px;
            font-weight: 300;
            margin: 24px 12px 12px;
            text-align: center;
        }
    }
</style>