zhangchen
2023-10-23 61b8b562f74691ae4dfe11008339450d0bc91ea1
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
<template>
    <div class="login-container" v-loading="clientLoading">
        <!-- 表单盒子 -->
        <div class="login_from_box">
            <div class="login_from_l">
                <div class="img_box"></div>
            </div>
            <div class="login_from_r">
                <div class="row_title">
                    <img :src="dtLogo" class="logo" alt="" srcset="">
                    <p class="title">{{ $t("login.title") }}</p>
                </div>
                <p class="sub_title">{{ $t("login.subTitle") }}</p>
                <!-- 登录表单 -->
                <el-form :model="loginFromData" class="login_form">
                    <el-form-item label="">
                        <el-input v-model="loginFromData.user_no" :placeholder="$t('login.form.placeholder.account')" clearable>
                            <template #prefix>
                                <i class="iconfont icon-yonghu"></i>
                            </template>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="">
                        <el-input v-model="loginFromData.user_password" :placeholder="$t('login.form.placeholder.pwd')" type="password" show-password>
                            <template #prefix>
                                <i class="iconfont icon-mima"></i>
                            </template>
                        </el-input>
                    </el-form-item>
                    <div class="form_other_box">
                        <div class="form_other_box_l">
                            <el-checkbox v-model="isAutoLogin" :label="$t('login.btn.auto')" />
                        </div>
                        <el-button type="info" link @click="forgetpasswordDialog = true">{{ $t("login.btn.forgetPwd") }}</el-button>
                    </div>
                    <el-button type="primary" round style="width: 100%" @click="submit" :loading="isLoading">{{ $t("login.btn.submit") }}</el-button>
                    <!-- 中文状态下的 -->
                    <div class="policy_box">
                        <el-checkbox v-model="isPolicy"
                            :style="{ 'white-space': nowLang }"
                            >{{ $t("login.btn.policyStart")
                            }}<span class="policy_text" @click="goPolicyPage('termsOfService')">{{ $t("login.btn.termsOfService") }}</span
                            >、<span class="policy_text" @click="goPolicyPage('legalNoticesAndPrivacyPolicy')">{{
                                $t("login.btn.legalNoticesAndPrivacyPolicy")
                            }}</span></el-checkbox
                        >
                    </div>
                    <!-- 英文状态下的 -->
                </el-form>
            </div>
        </div>
    </div>
    <!-- 忘记密码的弹出层 -->
    <el-dialog v-model="forgetpasswordDialog" :title="$t('login.forgetPwd.title')" width="30%" center @close="dialogClose">
        <Forgetpassword ref="fpasswordRef" @close="forgetpasswordDialogClose" />
    </el-dialog>
    <!-- 选择客户的弹出层 -->
    <el-dialog v-model="selectClientDialog" :title="$t('login.clientList.title')" width="20%" center :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false">
        <ClientList :data="clientData" @close="clientDialogClose" @submit="clientDialogSubmit" />
    </el-dialog>
    <!-- {{ formatLangElement }} -->
</template>
 
<script setup lang="ts" name="loginIndex">
import { reactive, ref, onMounted, computed } from "vue";
import { ElMessage } from "element-plus";
import { useI18n } from "vue-i18n";
import { useUser } from "/@/stores/user";
import { useSetting } from "/@/stores/setting";
import { api_get_client_list } from "/@/api/client";
import { LANG_VALUE } from "/@/common/enum";
import { useRouter } from "vue-router";
import logoPng from "/@/assets/images/dt_logo.png";
 
 
// @ts-ignore
import Forgetpassword from "./component/ForgetPwd/index.vue";
// @ts-ignore
import ClientList from "./component/Client/index.vue";
 
 
 
enum EPolicy {
    termsOfService = "https://gb8qxc.yuque.com/ewildp/ceg57x/obvyp1?",
    legalNoticesAndPrivacyPolicy = "https://gb8qxc.yuque.com/ewildp/ceg57x/mwg3ze?",
}
 
const { t } = useI18n();
const fpasswordRef = ref(null);
const store = useUser();
const storeSetting = useSetting();
const router = useRouter();
 
const dtLogo = ref(logoPng);
 
// 登录表单数据
const loginFromData: ILoginForm = reactive({
    user_no: "",
    user_password: "",
});
 
// 客户数据
const clientData = ref<IClientItem[]>([]);
 
// 是否自动登录
const isAutoLogin = ref<boolean>(false);
// 是否同意协议条款
const isPolicy = ref<boolean>(false);
// loading
const isLoading = ref<boolean>(false);
// 忘记密码的弹出层
const forgetpasswordDialog = ref<boolean>(false);
// 选择客户的弹出层
const selectClientDialog = ref<boolean>(false);
// 加载客户数据时的loading
const clientLoading = ref<boolean>(false);
 
 
 
 
const nowLang = computed(() => {
    return storeSetting.language === LANG_VALUE.En ? "pre-wrap" : "nowrap";
});
 
 
/**
 * 打开指定窗口
 */
const goPolicyPage = (name: EPolicy) => {
    const url = (EPolicy as unknown as Record<EPolicy, string>)[name];
    window.open(url);
};
 
 
 
const forgetpasswordDialogClose = () => {
    forgetpasswordDialog.value = false;
};
 
const dialogClose = () => {
    // @ts-ignore
    fpasswordRef.value.close();
};
 
const clientDialogClose = () => {
    selectClientDialog.value = false;
    ElMessage.error(t("login.msg.err.init"));
};
 
 
const clientDialogSubmit = async (options: any) => {
    try {
        await store.clientLogin(options.clientCode, options.clientName);
        // store.setClientName()
        selectClientDialog.value = false;
        ElMessage.success(t("login.msg.success.init"));
        router.push("/index")
    } catch (error) {
        
    }
};
 
/**
 * 提交表单
 */
const submit = async () => {
    if (!loginFromData.user_no) return ElMessage.error(t("login.msg.err.account"));
    if (!loginFromData.user_password) return ElMessage.error(t("login.msg.err.pwd"));
    if (!isPolicy.value) return ElMessage.error(t("login.msg.err.policy"));
 
    isLoading.value = true;
    try {
        const isHasManyClient = await store.login(loginFromData);
        isLoading.value = false;
 
        if(isHasManyClient) {
            // 存在多个客户
            await getClientData();
            selectClientDialog.value = true;
        } else {
            // 不存在直接走下面的流程
                ElMessage.success(t("login.msg.success.login"));
                router.push("/index")
        }
    } catch (error) {
        isLoading.value = false;
    }
};
 
 
 
const getClientData = async () => {
    clientLoading.value = true;
    try {
        const { data } = await api_get_client_list();
        clientData.value = data.list.map((e: any) => ({
            id: e.id,
            code: e.code,
            clientName: e.clientName
        }));
        clientLoading.value = false;
    } catch (error) {
        clientLoading.value = false;
        await store.logout();
    }
};
 
 
onMounted(async() => {
    // 页面每次加载时都要清除token一下,保证用户必须得选完客户才能进去
    // await store.logout();
});
 
</script>
 
<style scoped lang="scss">
@import "./index.scss";
 
::v-deep {
    .login_form {
        .el-input__wrapper {
            border-radius: 0;
            box-shadow: none;
            border-bottom: 1px solid #dedede;
        }
 
        .el-input__prefix {
            margin-right: 5px;
 
            &:first-child {
                margin-right: 3px;
            }
        }
    }
 
    // .el-checkbox {
    //     white-space: pre-wrap;
    // }
 
    .el-checkbox__label {
        font-size: 14px;
        color: #aaa;
    }
 
    .el-button.is-round {
        padding: 20px 15px;
    }
 
    .policy_box {
        .el-checkbox__label {
            transform: scale(0.8) translateX(-40px);
        }
 
        .el-checkbox__inner {
            border-radius: 50%;
            overflow: hidden;
        }
    }
}
</style>