index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <script setup>
  2. import { ref, onMounted, computed } 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. reasonsRefusalList();
  52. if (remenber.value.length) {
  53. userStore.saveAccountInfo({
  54. loginName: form.value.loginName,
  55. password: form.value.password,
  56. rememberPassword: true,
  57. });
  58. } else {
  59. userStore.saveAccountInfo({
  60. loginName: "",
  61. password: "",
  62. rememberPassword: false,
  63. });
  64. }
  65. // console.log(1111);
  66. } else {
  67. // console.log(12112);
  68. }
  69. } catch (error) {
  70. // console.log(error, 19089);
  71. }
  72. }
  73. async function getUserInfo() {
  74. try {
  75. const res = await ucardApi.getSingle();
  76. userStore.saveUserInfo(res.data);
  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. async function reasonsRefusalList() {
  91. try {
  92. const res = await ucardApi.reasonsRefusalList();
  93. if (res.code === 200) {
  94. pickFields(res.data);
  95. } else {
  96. uni.$u.toast(res.msg || t("login.msg0"));
  97. }
  98. } catch (error) {
  99. // console.log(error, 111);
  100. }
  101. }
  102. function pickFields(source, fields = ['content', 'enContent']) {
  103. const result = {}
  104. Object.entries(source).forEach(([key, value]) => {
  105. result[key] = fields.reduce((acc, f) => {
  106. acc[f] = value[f] ?? null
  107. return acc
  108. }, {})
  109. })
  110. userStore.saveReasonsOptions(result);
  111. }
  112. onMounted(() => {
  113. const accountInfo = userStore.accountInfo;
  114. if (accountInfo?.rememberPassword) {
  115. form.value.loginName = accountInfo?.loginName || "";
  116. form.value.password = accountInfo?.password || "";
  117. remenber.value = ["记住我"];
  118. } else {
  119. form.value.loginName = "";
  120. form.value.password = "";
  121. remenber.value = [];
  122. }
  123. });
  124. const inputType = ref("password");
  125. </script>
  126. <template>
  127. <cwg-page-wrapper>
  128. <view>
  129. <view class="company u-flex-y u-flex-y-center">
  130. <image src="/static/images/logo.png" class="company-icon" mode="widthFix"></image>
  131. </view>
  132. <view class="account">
  133. <view>
  134. <up-form :model="form" ref="uFormRef">
  135. <up-form-item label="" prop="loginName">
  136. <up-input :customStyle="customStyle" v-model="form.loginName" border="none"
  137. :placeholder="t('signin.form.email')">
  138. <template #prefix>
  139. <cwg-icon name="email-outline" :size="20" color="#000" />
  140. </template>
  141. </up-input>
  142. </up-form-item>
  143. <up-form-item label="" prop="password">
  144. <up-input :customStyle="customStyle" v-model="form.password" :type="inputType" border="none"
  145. :placeholder="t('signin.form.password')">
  146. <template #prefix>
  147. <cwg-icon name="lock-outline" :size="20" color="#000" />
  148. </template>
  149. </up-input>
  150. </up-form-item>
  151. </up-form>
  152. </view>
  153. <view class="u-flex u-flex-between u-flex-y-center">
  154. <view class="check-box">
  155. <up-checkbox-group v-model="remenber" @change="checkboxChange">
  156. <up-checkbox size="14" labelSize="14" labelColor="#666666" activeColor="#ea002a"
  157. :label="t('newSignin.item5')" name="记住我" class="wcg-checkbox"></up-checkbox>
  158. </up-checkbox-group>
  159. </view>
  160. <navigator url="/pages/login/reset" class="account-tip">
  161. <text>{{ t("signin.forget") }}</text>
  162. </navigator>
  163. </view>
  164. <view class="cwg-button">
  165. <u-button type="primary" class="" @click="submit">
  166. {{ t("signin.login") }}
  167. </u-button>
  168. </view>
  169. <!-- <navigator url="/pages/login/regist" class="account-tip">
  170. {{ t("signin.words") }}
  171. <text>{{ t("signin.signup") }}</text>
  172. </navigator> -->
  173. </view>
  174. </view>
  175. </cwg-page-wrapper>
  176. </template>
  177. <style lang="scss" scoped>
  178. @import "@/uni.scss";
  179. page {
  180. // padding: px2rpx(5) px2rpx(27);
  181. }
  182. button {
  183. background-color: #ea002a;
  184. font-size: px2rpx(14);
  185. font-weight: normal;
  186. height: px2rpx(44);
  187. line-height: px2rpx(44);
  188. }
  189. .company {
  190. padding: px2rpx(110) 0 px2rpx(50) 0;
  191. position: relative;
  192. align-items: flex-start !important;
  193. }
  194. .home-bg {
  195. position: absolute;
  196. width: 100%;
  197. height: 100%;
  198. top: 0;
  199. left: 0;
  200. z-index: -1;
  201. }
  202. .company-icon {
  203. width: px2rpx(117);
  204. }
  205. .company-head {
  206. .name {
  207. font-size: px2rpx(20);
  208. font-weight: 500;
  209. color: #ea002a;
  210. margin-bottom: px2rpx(2);
  211. }
  212. .into {
  213. font-size: px2rpx(14);
  214. font-weight: 350;
  215. color: #222222;
  216. }
  217. }
  218. .account {
  219. /* border-radius: px2rpx(16) px2rpx(16) px2rpx(0) px2rpx(0); */
  220. background-color: #ffffff;
  221. position: relative;
  222. top: px2rpx(-15);
  223. /* box-shadow: 0 -1px 4px rgba(97, 96, 96, 0.1); */
  224. }
  225. .input {
  226. height: px2rpx(44);
  227. border-radius: px2rpx(8);
  228. background: #f7f8fa;
  229. padding: 0 px2rpx(20) !important;
  230. position: relative;
  231. }
  232. .account-icon {
  233. width: px2rpx(12);
  234. height: px2rpx(14) !important;
  235. margin-right: px2rpx(5);
  236. }
  237. :deep(.u-input__content__prefix-icon) {
  238. height: px2rpx(20);
  239. }
  240. .regiset-btn {
  241. margin: px2rpx(20) 0;
  242. }
  243. .account-tip {
  244. color: #666666;
  245. font-size: px2rpx(14);
  246. text-align: center;
  247. text {
  248. color: #ea002a;
  249. }
  250. }
  251. :deep(.u-form-item__body) {
  252. padding: 0 !important;
  253. padding-bottom: px2rpx(14) !important;
  254. }
  255. :deep(.wcg-checkbox) {
  256. padding: 0 !important;
  257. /* .u-checkbox__icon-wrap {
  258. background-color: #ea002a !important;
  259. border-color: #ea002a !important;
  260. } */
  261. }
  262. .cwg-button {
  263. padding-top: px2rpx(14) !important;
  264. }
  265. </style>