You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <!-- 密码登录 -->
  2. <template>
  3. <view class="login-main as-gravity-center as-layout-vertical">
  4. <image :src="`${$imgUrl}login/logo.png`" class="logo" mode="aspectFill"></image>
  5. <view class="title">九州ETC</view>
  6. <view class="form">
  7. <view class="form-input">
  8. <view> +86</view>
  9. <image :src="`${$imgUrl}common/arror_down_black.png`" class="arror" mode="aspectFill" />
  10. <input class="input" v-model="state.username" focus placeholder="请输入手机号"
  11. placeholder-class="form-placeholder" type="number" maxlength="11" />
  12. </view>
  13. <view class="form-input" v-if="state.loginType === 'pwd'">
  14. <input class="input" v-model="state.password" type="text" placeholder="请输入密码"
  15. placeholder-class="form-placeholder" :password="state.isPwdType ? true : false" />
  16. <image :src="`${$imgUrl}login/${
  17. state.isPwdType ? 'icon_eye_close' : 'icon_eye_open'
  18. }.png`" class="eye" @click="state.isPwdType = !state.isPwdType" mode="aspectFill"></image>
  19. </view>
  20. <view class="form-input" v-if="state.loginType === 'code'">
  21. <input class="input" v-model="state.code" placeholder="请输入验证码" placeholder-class="form-placeholder"
  22. maxlength="6" type="number" />
  23. <verification-code :bg="false" :mobile="state.username" :businessType="0"></verification-code>
  24. </view>
  25. </view>
  26. <view class="btn">
  27. <submit-button title="登录" @submit="doLogin"></submit-button>
  28. </view>
  29. <view class="agreement">
  30. <checkbox-group @change="checkboxChange" class="group">
  31. <checkbox :checked="state.checked" color="#00B38B" size="30" icon-size="30" label-size="24"
  32. style="transform:scale(0.85)">
  33. </checkbox>
  34. <label>我已阅读并同意</label>
  35. </checkbox-group>
  36. <view class="txt-green" @click="toRead">《平台用户服务隐私协议》</view>
  37. </view>
  38. <view class="btns as-layout-horizontal">
  39. <view class="as-layout-vertical as-gravity-center" @click="navTo('/login/register-step1')">
  40. <view class="bg blue as-gravity-center">
  41. <image :src="`${$imgUrl}login/icon_register.png`" class="img" mode="aspectFill" />
  42. </view>
  43. <view class="label">注册账号</view>
  44. </view>
  45. <view class="as-layout-vertical as-gravity-center" @click="
  46. state.loginType === 'pwd'
  47. ? (state.loginType = 'code')
  48. : (state.loginType = 'pwd')
  49. ">
  50. <view class="bg orange as-gravity-center">
  51. <image :src="`${$imgUrl}login/icon_code.png`" class="img" mode="aspectFill" />
  52. </view>
  53. <view class="label">{{
  54. state.loginType === "pwd" ? "验证码登录" : "密码登录"
  55. }}</view>
  56. </view>
  57. <view class="as-layout-vertical as-gravity-center" @click="navTo('/login/forget-pwd-step1')">
  58. <view class="bg purple as-gravity-center">
  59. <image :src="`${$imgUrl}login/icon_pwd.png`" class="img" mode="aspectFill" />
  60. </view>
  61. <view class="label">忘记密码</view>
  62. </view>
  63. <!-- <view class="as-layout-vertical as-gravity-center" @click="navTo('/login/change-phone')">
  64. <view class="bg purple as-gravity-center">
  65. <image :src="`${$imgUrl}login/icon_pwd.png`" class="img" mode="aspectFill" />
  66. </view>
  67. <view class="label">修改手机号</view>
  68. </view> -->
  69. </view>
  70. </view>
  71. </template>
  72. <script setup lang="ts">
  73. import { reactive } from "vue";
  74. import { checkStr, msg, navTo, subscribeMessages} from "@/utils/utils";
  75. import { onLoad, onUnload } from "@dcloudio/uni-app";
  76. import { login, loginCode, loginTime, wechatAppID, customerQuery, userInfoIndex } from "@/utils/network/api.js";
  77. import { requestNew} from "@/utils/network/request.js";
  78. import { useUserStore } from "@/stores/user";
  79. import { setItem,getItem } from "@/utils/storage";
  80. const userStore = useUserStore();
  81. const { fetchToken, saveUserInfo, setIsNewLogin } = userStore;
  82. const state = reactive({
  83. checked: false, //是否勾选协议
  84. isPwdType: true, //是不是密码类型
  85. loginType: "code", //pwd-密码登录 code-验证码登录
  86. username: "", //用户名
  87. password: "", //密码
  88. code: "", //验证码
  89. back: 0, //从app扫码看协议过来 登录了 还需要回到手机号验证页面 0 是原本的登录 1 要回去的登录(从哪来回哪去) 2运维跳转过来得中转页
  90. params:{}
  91. });
  92. onLoad((option) => {
  93. if (option.back == 1) {
  94. state.back = option.back
  95. }
  96. if (option.back == 2) {
  97. state.back = option.back
  98. state.params = JSON.parse(decodeURIComponent(option.params))
  99. }
  100. uni.$on("login", (data) => {
  101. state.username = data.phone;
  102. });
  103. });
  104. onUnload(() => {
  105. uni.$off("login");
  106. });
  107. const checkboxChange = (e) => {
  108. console.log(e);
  109. state.checked = !state.checked;
  110. };
  111. // 去协议页面
  112. const toRead = () => {
  113. navTo("/login/agreement")
  114. }
  115. /* 登录 */
  116. const doLogin = () => {
  117. if (!state.username) {
  118. msg("请输入手机号!");
  119. return;
  120. }
  121. if (state.loginType === "pwd" && !state.password) {
  122. msg("请输入密码!");
  123. return;
  124. }
  125. if (state.loginType === "code" && !state.code) {
  126. msg("请输入验证码!");
  127. return;
  128. }
  129. if (!checkStr(state.username, "mobile")) {
  130. msg("请输入正确的手机号!");
  131. return;
  132. }
  133. if (!state.checked) {
  134. msg("请勾选我已阅读并同意《平台用户服务隐私协议》");
  135. return;
  136. }
  137. // 测试环境的时候添加哥测试id
  138. if (process.env.NODE_ENV === 'development') {
  139. setItem("mpOpenId", 'ogb3atz0dIAHvUMovfR-eSXHdmOs');
  140. }
  141. console.log("mpOpenId",getItem('mpOpenId'))
  142. if(!getItem('mpOpenId')){
  143. navTo(`/subpackage/after-sale/wxWebView`)
  144. return;
  145. }
  146. //判断是验证码登录,还是账号密码登录
  147. if (state.loginType === "code") {
  148. reqLogin(loginCode, {
  149. mobile: state.username,
  150. code: state.code,
  151. loginTime: loginTime,
  152. });
  153. } else {
  154. reqLogin(login, {
  155. mobile: state.username,
  156. password: state.password,
  157. loginTime: loginTime,
  158. });
  159. }
  160. };
  161. /* 执行登录 */
  162. const reqLogin = (code : string, data : object) => {
  163. console.log(code, data);
  164. const options = {
  165. type: 2,
  166. data: data,
  167. method: "POST",
  168. showLoading: true,
  169. };
  170. requestNew(code, options).then((res) => {
  171. const result = res;
  172. console.log(result);
  173. console.log(typeof (result));
  174. fetchToken(result.code).then((data : any) => {
  175. console.log("登录", data);
  176. setItem('mobile', state.username)
  177. subscribeMessages();
  178. msg("登录成功!");
  179. setIsNewLogin(true)
  180. let getUserInfo = requestNew(userInfoIndex, {
  181. type: 2,
  182. data: {},
  183. method: "POST",
  184. showLoading: true,
  185. });
  186. let getEtcAccounts = requestNew(customerQuery, {
  187. type: 2,
  188. data: {},
  189. method: "POST",
  190. showLoading: true,
  191. })
  192. Promise.all([getUserInfo, getEtcAccounts]).then(reses => {
  193. let userInfoRes = reses[0];
  194. if (userInfoRes.mobile) {
  195. saveUserInfo(userInfoRes);
  196. }
  197. let userCustomerId = userInfoRes.customerId || '';
  198. let etcAccounts = reses[1];
  199. let customerObj = etcAccounts.find(val => val.customerId == userCustomerId);
  200. if(customerObj) {
  201. setItem('customerObj', customerObj);
  202. }
  203. })
  204. uni.$emit("refreshOrder");
  205. if (state.back == 1) {
  206. uni.navigateBack({
  207. delta: 1
  208. })
  209. } else if (state.back == 2) {
  210. const params = encodeURIComponent(JSON.stringify(state.params))
  211. uni.redirectTo({
  212. url:`/subpackage/after-sale/transfer-page?params=${params}`
  213. })
  214. } else{
  215. uni.switchTab({
  216. url: '/pages/index/index'
  217. })
  218. }
  219. });
  220. });
  221. };
  222. </script>
  223. <style lang="scss" scoped>
  224. .login-main {
  225. border-top: 1rpx solid #dcdcdc;
  226. padding: 22rpx 30rpx 140rpx;
  227. .logo {
  228. width: 260rpx;
  229. height: 160rpx;
  230. }
  231. .group {
  232. display: flex;
  233. align-items: center;
  234. }
  235. .title {
  236. font-size: 46rpx;
  237. color: #333333;
  238. margin-top: 30rpx;
  239. font-weight: 600;
  240. }
  241. .form {
  242. width: 100%;
  243. margin-top: 100rpx;
  244. .form-input {
  245. display: flex;
  246. flex-direction: row;
  247. align-items: center;
  248. height: 90rpx;
  249. border-bottom: 1rpx solid #dcdcdc;
  250. padding: 0rpx 12rpx;
  251. color: #333333;
  252. &:last-child {
  253. margin-top: 50rpx;
  254. }
  255. .input {
  256. flex: 1;
  257. padding-right: 48rpx;
  258. font-size: 28rpx;
  259. font-family: Microsoft YaHei;
  260. background-color: transparent;
  261. }
  262. .arror {
  263. width: 28rpx;
  264. height: 25rpx;
  265. margin-left: 16rpx;
  266. margin-right: 40rpx;
  267. }
  268. .eye {
  269. width: 48rpx;
  270. height: 48rpx;
  271. }
  272. }
  273. .form-placeholder {
  274. color: #999999;
  275. }
  276. }
  277. .btn {
  278. width: 100%;
  279. margin: 120rpx 40rpx 50rpx;
  280. }
  281. .agreement {
  282. font-size: 24rpx;
  283. display: flex;
  284. align-items: center;
  285. .txt-grey {
  286. color: #666666;
  287. }
  288. .txt-green {
  289. color: #00b38b;
  290. }
  291. :deep(.u-checkbox) {
  292. margin-right: -20rpx;
  293. }
  294. }
  295. .btns {
  296. width: 100%;
  297. margin-top: 125rpx;
  298. justify-content: space-around;
  299. padding: 0px 8rpx;
  300. .bg {
  301. width: 80rpx;
  302. height: 80rpx;
  303. border-radius: 50%;
  304. .img {
  305. width: 48rpx;
  306. height: 48rpx;
  307. }
  308. }
  309. .blue {
  310. background-color: #1d9cff;
  311. }
  312. .orange {
  313. background-color: #feb654;
  314. }
  315. .purple {
  316. background-color: #8060ff;
  317. }
  318. .label {
  319. font-size: 26rpx;
  320. color: #333333;
  321. margin-top: 30rpx;
  322. }
  323. }
  324. }
  325. </style>