index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <script setup>
  2. import { ref, onMounted, watch } from "vue";
  3. import { post } from "@/utils/request";
  4. import { userToken } from "@/composables/config";
  5. import { userApi } from "@/api/user";
  6. import { ucardApi } from "@/api/ucard";
  7. import useUserStore from "@/stores/use-user-store";
  8. import useRouter from "@/hooks/useRouter";
  9. import { useI18n } from "vue-i18n";
  10. const router = useRouter();
  11. const { t } = useI18n();
  12. const userStore = useUserStore();
  13. // 响应式表单数据
  14. const form = ref({
  15. loginName: "",
  16. password: "",
  17. });
  18. function submit() {
  19. if (!form.value.loginName) {
  20. uni.$u.toast(t("signin.form.email"));
  21. return;
  22. }
  23. if (!form.value.password) {
  24. uni.$u.toast(t("signin.form.password"));
  25. return;
  26. }
  27. handleLogin();
  28. }
  29. const customStyle = {
  30. height: "44px",
  31. "border-radius": "8px",
  32. background: "#f7f8fa",
  33. padding: "0 20px !important",
  34. position: "relative",
  35. };
  36. const remenber = ref([]);
  37. const checkboxChange = (e) => {
  38. remenber.value = e;
  39. };
  40. const fetchUserList = (params) => post("/Login/AcctLogin", params);
  41. async function handleLogin() {
  42. try {
  43. const res = await userApi.login({
  44. loginName: form.value.loginName,
  45. password: form.value.password,
  46. });
  47. if (res.code === 200) {
  48. userToken.value = res.data;
  49. uni.$u.toast(t("login.msg0_1"));
  50. getUserInfo();
  51. if (remenber.value.length) {
  52. userStore.saveAccountInfo({
  53. loginName: form.value.loginName,
  54. password: form.value.password,
  55. rememberPassword: true,
  56. });
  57. } else {
  58. userStore.saveAccountInfo({
  59. loginName: "",
  60. password: "",
  61. rememberPassword: false,
  62. });
  63. }
  64. console.log(1111);
  65. } else {
  66. console.log(12112);
  67. }
  68. } catch (error) {
  69. console.log(error, 19089);
  70. }
  71. }
  72. async function getUserInfo() {
  73. try {
  74. const res = await ucardApi.getSingle();
  75. userStore.saveUserInfo(res.data);
  76. console.log(res, 111);
  77. if (res.code === 200) {
  78. if (!res.data || res.data.approveStatus != 2) {
  79. router.push("/pages/mine/improve");
  80. } else {
  81. router.push("/pages/card/index");
  82. }
  83. } else {
  84. uni.$u.toast(res.msg || t("login.msg0"));
  85. }
  86. } catch (error) {
  87. console.log(error, 111);
  88. }
  89. }
  90. onMounted(() => {
  91. const accountInfo = userStore.accountInfo;
  92. if (accountInfo?.rememberPassword) {
  93. form.value.loginName = accountInfo?.loginName || "";
  94. form.value.password = accountInfo?.password || "";
  95. remenber.value = ["记住我"];
  96. } else {
  97. form.value.loginName = "";
  98. form.value.password = "";
  99. remenber.value = [];
  100. }
  101. });
  102. const inputType = ref("password");
  103. </script>
  104. <template>
  105. <cwg-page-wrapper>
  106. <view>
  107. <view class="company u-flex-y u-flex-y-center">
  108. <image src="/static/images/logo.png" class="company-icon" mode="widthFix"></image>
  109. </view>
  110. <view class="account">
  111. <view>
  112. <up-form :model="form" ref="uFormRef">
  113. <up-form-item label="" prop="loginName">
  114. <up-input :customStyle="customStyle" v-model="form.loginName" border="none"
  115. :placeholder="t('signin.form.email')">
  116. <template #prefix>
  117. <cwg-icon name="email-outline" :size="20" color="#000" />
  118. </template>
  119. </up-input>
  120. </up-form-item>
  121. <up-form-item label="" prop="password">
  122. <up-input :customStyle="customStyle" v-model="form.password" :type="inputType" border="none"
  123. :placeholder="t('signin.form.password')">
  124. <template #prefix>
  125. <cwg-icon name="lock-outline" :size="20" color="#000" />
  126. </template>
  127. </up-input>
  128. </up-form-item>
  129. </up-form>
  130. </view>
  131. <view class="u-flex u-flex-between u-flex-y-center">
  132. <view class="check-box">
  133. <up-checkbox-group v-model="remenber" @change="checkboxChange">
  134. <up-checkbox size="14" labelSize="14" labelColor="#666666" activeColor="#ea002a"
  135. :label="t('newSignin.item5')" name="记住我" class="wcg-checkbox"></up-checkbox>
  136. </up-checkbox-group>
  137. </view>
  138. <navigator url="/pages/login/reset" class="account-tip">
  139. <text>{{ t("signin.forget") }}</text>
  140. </navigator>
  141. </view>
  142. <view class="cwg-button">
  143. <u-button type="primary" class="" @click="submit">
  144. {{ t("signin.login") }}
  145. </u-button>
  146. </view>
  147. <!-- <navigator url="/pages/login/regist" class="account-tip">
  148. {{ t("signin.words") }}
  149. <text>{{ t("signin.signup") }}</text>
  150. </navigator> -->
  151. </view>
  152. </view>
  153. </cwg-page-wrapper>
  154. </template>
  155. <style lang="scss" scoped>
  156. @import "@/uni.scss";
  157. page {
  158. // padding: px2rpx(5) px2rpx(27);
  159. }
  160. button {
  161. background-color: #ea002a;
  162. font-size: px2rpx(14);
  163. font-weight: normal;
  164. height: px2rpx(44);
  165. line-height: px2rpx(44);
  166. }
  167. .company {
  168. padding: px2rpx(110) 0 px2rpx(50) 0;
  169. position: relative;
  170. align-items: flex-start !important;
  171. }
  172. .home-bg {
  173. position: absolute;
  174. width: 100%;
  175. height: 100%;
  176. top: 0;
  177. left: 0;
  178. z-index: -1;
  179. }
  180. .company-icon {
  181. width: px2rpx(117);
  182. }
  183. .company-head {
  184. .name {
  185. font-size: px2rpx(20);
  186. font-weight: 500;
  187. color: #ea002a;
  188. margin-bottom: px2rpx(2);
  189. }
  190. .into {
  191. font-size: px2rpx(14);
  192. font-weight: 350;
  193. color: #222222;
  194. }
  195. }
  196. .account {
  197. /* border-radius: px2rpx(16) px2rpx(16) px2rpx(0) px2rpx(0); */
  198. background-color: #ffffff;
  199. position: relative;
  200. top: px2rpx(-15);
  201. /* box-shadow: 0 -1px 4px rgba(97, 96, 96, 0.1); */
  202. }
  203. .input {
  204. height: px2rpx(44);
  205. border-radius: px2rpx(8);
  206. background: #f7f8fa;
  207. padding: 0 px2rpx(20) !important;
  208. position: relative;
  209. }
  210. .account-icon {
  211. width: px2rpx(12);
  212. height: px2rpx(14) !important;
  213. margin-right: px2rpx(5);
  214. }
  215. :deep(.u-input__content__prefix-icon) {
  216. height: px2rpx(20);
  217. }
  218. .regiset-btn {
  219. margin: px2rpx(20) 0;
  220. }
  221. .account-tip {
  222. color: #666666;
  223. font-size: px2rpx(14);
  224. text-align: center;
  225. text {
  226. color: #ea002a;
  227. }
  228. }
  229. :deep(.u-form-item__body) {
  230. padding: 0 !important;
  231. padding-bottom: px2rpx(14) !important;
  232. }
  233. :deep(.wcg-checkbox) {
  234. padding: 0 !important;
  235. padding-bottom: px2rpx(14) !important;
  236. /* .u-checkbox__icon-wrap {
  237. background-color: #ea002a !important;
  238. border-color: #ea002a !important;
  239. } */
  240. }
  241. </style>