guoyujie
9 天以前 a6c698f7418c1b0ea6202f068993d74a3347b0e6
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
<template>
    <web-view v-if="viewShow" :src="downloadPage" style="width: 100%;height:90%"></web-view>
    <view class="content" v-else>
        <image class="logo" src="/static/favicon.ico"></image>
        <view class="text-area">
            <text class="title">NorthGlass</text>
        </view>
        <view class="text-area">
            <text class="title">{{ip}}({{store.version}})</text>
        </view>
        <view class="text-area" >
            <uni-data-select style="width:40vw;text-align: center;"
                            placeholder="请选择班次"
                            v-model="store.user.class"
                            :localdata="classList"
                        />
        </view>
        <view class="text-area" >
            <view>
                <!-- <uni-easyinput @blur="searchUser" v-model="searchUserList.userName"/> -->
                <uni-easyinput 
                class='input_1'
                placeholder="请输入账号"
                style="text-align: center;"
                v-model="userForm.userId"/>
            </view>
        </view>
        <!-- <view class="text-area">
            <view>
                <uni-data-select style="width:50vw"
                                v-model="userForm.userId"
                                :localdata="users"
                            ></uni-data-select>
            </view>                                                    
        </view> -->
        <view class="text-area" >
            <uni-easyinput
                class='input_1'
                style="text-align: center;"
                placeholder="请输入密码" 
                :passwordIcon='false'
                v-model="userForm.pass" 
                type="password" />
        </view>
        
        <view class="text-area" >
            <button @click="login" class="login" type="primary" size="mini">登陆</button>
        </view>
        <text  
            @click="initApp"
            style="color:#007aff;text-decoration:underline;margin-top: 8rem;">初始化</text>
        
        
        <view>
            <!-- 提示信息弹窗 -->
            <uni-popup ref="message" type="message">
                <uni-popup-message :type="msgType" :message="messageText" :duration="2000" />
            </uni-popup>
        </view>
    </view>
</template>
 
<script  setup>
    import {onMounted, reactive,ref} from "vue"
  import userInfo from '@/stores/userInfo'
    import request from '@/utils/request'
    import {ip,webPort} from '@/utils/config.js'
    
  const store=userInfo()
    let searchUserList = ref({
        userName:null
    })
    const userForm = reactive({
      userId: uni.getStorageSync('userId') || null,
      pass: uni.getStorageSync('pass') || null
    })
    let users = ref([])
    const message = ref(null)
    const type=ref('center')
    const msgType=ref('success')
    const messageText=ref('')
    const viewShow = ref(false)
    const downloadPage = ref(`http://${ip}:${webPort}/#/app`)
    let ipVal = ref(null)
    
    const classList = ref([
        {text:'早班',value:"早班"},
        {text:'晚班',value:"晚班"}
    ])
    
    onMounted(async()=>{
        if(ip===null){
            uni.reLaunch({
              url: `/pages/login/login`
            })
            return
        }
        
        await getAppVersion() 
    })
    const searchUser = () => {
        getUserList()
    }
    //获取app版本号
    const getAppVersion =async () => {
        await request.post(`/appVersion/searchVersion`).then((res) => {
            if(res.code==='200'){
                if(res.data.version!==store.version){
                    if(uni.getSystemInfoSync().platform==='android'){
                        plus.runtime.openURL( downloadPage.value)
                        plus.runtime.quit()
                        return false
                    }else{
                        viewShow.value = !viewShow.value
                    }    
                }
            }
        }).catch(error =>{
            messageToggle('error',error)
        })
    }
    
    //查用户列表
    const getUserList = async()=> {
        await request.post(`/userInfo/findByAddress`,searchUserList.value).then((res) => {
            if(res.code==='200'){
                users.value = res.data.users[0]
            }
        })
    }
    //提示打开
    const messageToggle = (type,msg) =>{
        msgType.value = type
        messageText.value = msg
        message.value.open()
    }
    
    const login = async () => {
        await getAppVersion()
    userForm.pass = btoa(userForm.pass)
        store.cleanInfo()
        if(store.user.class === null || store.user.class === ""){
            messageToggle('error','请输入班次信息')
            return false
        }
        
        request.post('/userInfo/login',userForm).then((res) => {
            if(res['code']==200 && res['data']){
                store.$patch({user:res.data})
        uni.reLaunch({
          url: `/pages/mainView/mainView`
        })
                uni.setStorageSync('userId', userForm.userId);
                uni.setStorageSync('pass', atob(userForm.pass));
            } else {
                messageToggle('error','请输入正确的账号密码')
                return false
            }
        }).catch(error => {
            messageToggle('error',error)
            return false
        }).then(() => {
            userForm.pass = atob(userForm.pass)
        })
    }
    
    const initApp = () => {
        uni.removeStorage({
            key: 'ip'
        });
        plus.runtime.restart()
    }
 
</script>
 
<style>
    /* .login{
        width: 100px;height: 45px;margin: 0 auto;
    } */
    .content {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        margin-top: -40%;
    }
 
    .logo {
        height: 200rpx;
        width: 200rpx;
        margin-top: 200rpx;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 50rpx;
    }
 
    .text-area {
        display: flex;
        justify-content: center;
        padding-bottom: 1rem;
    }
</style>