index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="login flex justify-center items-center h-full">
  3. <img class="logo" src="../../assets/imgs/login_logo.png" />
  4. <div class="login-bg flex justify-center items-center">
  5. <div class="login-bg-inner-box text-center">
  6. <img src="../../assets/imgs/login_bg_inner.png" />
  7. <div class="title1">欢 迎 使 用</div>
  8. <div class="title2">项目质量控制管理平台</div>
  9. </div>
  10. </div>
  11. <div class="login-box">
  12. <div class="title1 flex justify-between items-center">
  13. <span>{{ forgetStatus ? '忘记密码' : '输入信息' }}</span>
  14. <t-button
  15. v-if="forgetStatus"
  16. variant="outline"
  17. @click="forgetStatus = false"
  18. >
  19. <template #icon><RollbackIcon /></template>
  20. 返回登录
  21. </t-button>
  22. <t-button
  23. v-else
  24. variant="outline"
  25. @click="loginType = loginType === 'ACCOUNT' ? 'PHONE' : 'ACCOUNT'"
  26. >
  27. <template #icon><SwapRightIcon /></template>
  28. {{ loginType === 'ACCOUNT' ? '手机号' : '账号' }}登录
  29. </t-button>
  30. </div>
  31. <div class="title2" v-if="forgetStatus">{{ `请输入新的账号与密码` }}</div>
  32. <div class="title2" v-else>{{
  33. `请输入${loginType === 'ACCOUNT' ? '账号与密码' : '手机号与验证码'}`
  34. }}</div>
  35. <template v-if="!forgetStatus">
  36. <t-form
  37. ref="form"
  38. :data="formData"
  39. :label-width="0"
  40. class="login-form"
  41. :rules="rules"
  42. v-if="loginType === 'ACCOUNT'"
  43. >
  44. <t-form-item name="loginName">
  45. <t-input
  46. v-model="formData.loginName"
  47. clearable
  48. placeholder="请输入账号"
  49. size="large"
  50. @enter="loginHandle"
  51. >
  52. <template #prefix-icon>
  53. <desktop-icon />
  54. </template>
  55. </t-input>
  56. </t-form-item>
  57. <t-form-item name="password">
  58. <t-input
  59. v-model="formData.password"
  60. type="password"
  61. clearable
  62. placeholder="请输入密码"
  63. size="large"
  64. @enter="loginHandle"
  65. >
  66. <template #prefix-icon>
  67. <lock-on-icon />
  68. </template>
  69. </t-input>
  70. </t-form-item>
  71. </t-form>
  72. <t-form
  73. v-else
  74. ref="form2"
  75. :data="formData2"
  76. :label-width="0"
  77. class="login-form"
  78. :rules="rules2"
  79. >
  80. <t-form-item name="mobileNumber">
  81. <t-input
  82. v-model="formData2.mobileNumber"
  83. clearable
  84. placeholder="请输入你的手机号"
  85. size="large"
  86. >
  87. <template #prefix-icon>
  88. <CallIcon />
  89. </template>
  90. </t-input>
  91. </t-form-item>
  92. <t-form-item name="code">
  93. <div class="flex items-center">
  94. <t-input
  95. style="width: 170px"
  96. v-model="formData2.code"
  97. clearable
  98. placeholder="验证码"
  99. size="large"
  100. >
  101. <template #prefix-icon>
  102. <MobileIcon />
  103. </template>
  104. </t-input>
  105. <t-button
  106. class="m-l-20px"
  107. style="width: 110px"
  108. :loading="loading"
  109. @click="getCode"
  110. >{{ isActive ? lastSeconds + 's' : '获取验证码' }}</t-button
  111. >
  112. </div>
  113. </t-form-item>
  114. </t-form>
  115. <t-link theme="primary" class="m-t-20px" @click="forgetStatus = true"
  116. >忘记密码</t-link
  117. >
  118. <t-button
  119. block
  120. class="m-t-30px"
  121. @click="loginHandle"
  122. size="large"
  123. theme="primary"
  124. >登 录</t-button
  125. >
  126. </template>
  127. <ForgetPwd v-else @success="findSuccess" />
  128. </div>
  129. </div>
  130. <!-- <button @click="loginHandle" class="m-t-10px">登录!</button> -->
  131. </template>
  132. <script setup name="Login">
  133. import { ref, reactive, computed, watch } from 'vue';
  134. import {
  135. DesktopIcon,
  136. LockOnIcon,
  137. RollbackIcon,
  138. SwapRightIcon,
  139. CallIcon,
  140. MobileIcon,
  141. } from 'tdesign-icons-vue-next';
  142. import { useRoute, useRouter } from 'vue-router';
  143. import { useUserStore, useAppStore } from '@/store';
  144. import { MessagePlugin } from 'tdesign-vue-next';
  145. import { getBase64 } from '@/utils/crypto';
  146. import ForgetPwd from './forget-pwd.vue';
  147. import { useRequest } from 'vue-request';
  148. import { getVerifyCode } from '@/api/user';
  149. import { useIntervalFn } from '@vueuse/core';
  150. const { run, loading } = useRequest(getVerifyCode, {
  151. onSuccess: () => {
  152. MessagePlugin.success('验证码已发送');
  153. },
  154. });
  155. const lastSeconds = ref(10);
  156. const countdown = () => {
  157. if (lastSeconds.value == 0) {
  158. pause();
  159. } else {
  160. lastSeconds.value = lastSeconds.value - 1;
  161. }
  162. };
  163. const { pause, resume, isActive } = useIntervalFn(
  164. () => {
  165. countdown();
  166. },
  167. 1000,
  168. { immediate: false }
  169. );
  170. const getCode = () => {
  171. if (!formData2.mobileNumber) {
  172. MessagePlugin.error('请先输入手机号');
  173. return;
  174. }
  175. run({
  176. mobileNumber: formData2.mobileNumber,
  177. });
  178. // resume();
  179. };
  180. const loginType = ref('ACCOUNT');
  181. const appStore = useAppStore();
  182. const forgetStatus = ref(false);
  183. const form = ref(null);
  184. const form2 = ref(null);
  185. const route = useRoute();
  186. const router = useRouter();
  187. const formData = reactive({
  188. loginName: '',
  189. password: '',
  190. });
  191. const formData2 = reactive({
  192. mobileNumber: '',
  193. code: '',
  194. });
  195. const rules = {
  196. loginName: [
  197. { required: true, message: '请输入账号', type: 'error', trigger: 'change' },
  198. ],
  199. password: [
  200. { required: true, message: '请输入密码', type: 'error', trigger: 'change' },
  201. ],
  202. };
  203. const rules2 = {
  204. mobileNumber: [
  205. {
  206. required: true,
  207. message: '请输入手机号',
  208. type: 'error',
  209. trigger: 'change',
  210. },
  211. ],
  212. code: [
  213. {
  214. required: true,
  215. message: '请输入验证码',
  216. type: 'error',
  217. trigger: 'change',
  218. },
  219. ],
  220. };
  221. const userStore = useUserStore();
  222. const loginHandle = () => {
  223. (loginType.value === 'ACCOUNT' ? form.value : form2.value)
  224. .validate()
  225. .then(async (result) => {
  226. const redirect = route.query.redirect
  227. ? route.query.redirect
  228. : '/my-workbenches';
  229. if (result === true) {
  230. let params =
  231. loginType.value === 'ACCOUNT'
  232. ? {
  233. loginName: formData.loginName,
  234. password: getBase64(formData.password),
  235. }
  236. : formData2;
  237. await userStore.login({
  238. ...params,
  239. type: loginType.value,
  240. });
  241. await userStore.requestUserMenu();
  242. await appStore.getFlowParams();
  243. if (redirect) {
  244. router.push(redirect);
  245. } else {
  246. router.push({ name: userStore.menus[0].name });
  247. }
  248. }
  249. });
  250. };
  251. const findSuccess = () => {
  252. forgetStatus.value = false;
  253. formData.loginName = '';
  254. formData.password = '';
  255. };
  256. </script>
  257. <style lang="less" scoped>
  258. .login {
  259. background: linear-gradient(180deg, #f4f9ff 0%, #d7eaff 100%);
  260. position: relative;
  261. min-height: 550px;
  262. .logo {
  263. width: 180px;
  264. z-index: 100;
  265. top: 48px;
  266. left: 48px;
  267. position: absolute;
  268. }
  269. .login-bg {
  270. position: absolute;
  271. top: 80px;
  272. bottom: 80px;
  273. left: 0;
  274. width: 70%;
  275. z-index: 99;
  276. background: url(../../assets//imgs/login_bg_grid.png) center center
  277. no-repeat;
  278. background-size: contain;
  279. .login-bg-inner-box {
  280. img {
  281. height: 260px;
  282. margin-bottom: 20px;
  283. }
  284. .title1 {
  285. font-size: 32px;
  286. color: #262626;
  287. margin-bottom: 15px;
  288. font-weight: bold;
  289. line-height: 40px;
  290. }
  291. .title2 {
  292. font-size: 20px;
  293. color: #8c8c8c;
  294. line-height: 28px;
  295. }
  296. }
  297. }
  298. .login-box {
  299. width: 350px;
  300. background: #fff;
  301. box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.08);
  302. border-radius: 8px;
  303. border: 1px solid #e5e6eb;
  304. padding: 24px;
  305. position: absolute;
  306. left: 60%;
  307. z-index: 101;
  308. .title1 {
  309. span {
  310. font-size: 20px;
  311. font-weight: bold;
  312. color: #262626;
  313. line-height: 32px;
  314. }
  315. }
  316. .title2 {
  317. font-size: 14px;
  318. color: #8c8c8c;
  319. line-height: 24px;
  320. margin-top: 4px;
  321. margin-bottom: 28px;
  322. }
  323. }
  324. }
  325. </style>