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.

login.vue 9.0KB

3 settimane fa
3 settimane fa
3 settimane fa
3 settimane fa
1 anno fa
3 settimane fa
6 mesi fa
4 mesi fa
1 anno fa
3 settimane fa
3 settimane fa
3 settimane fa
1 anno fa
7 mesi fa
3 settimane fa
3 settimane fa
1 anno fa
3 settimane fa
3 settimane fa
1 anno fa
3 settimane fa
3 settimane fa
7 mesi fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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"></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>
  64. </view>
  65. <!-- <view class="mask">
  66. <view class="uni-list">
  67. <checkbox-group @change="checkboxChangeLogin">
  68. <label class="uni-list-cell uni-list-cell-pd" v-for="item in state.items" :key="item.value">
  69. <view>
  70. <checkbox :value="item.value" :checked="item.checked" />
  71. </view>
  72. <view>{{item.name}}</view>
  73. </label>
  74. </checkbox-group>
  75. <submit-button title="确定" @submit="sure"></submit-button>
  76. </view>
  77. </view> -->
  78. </template>
  79. <script setup lang="ts">
  80. import { reactive } from "vue";
  81. import { checkStr, msg, navTo, subscribeMessages } from "@/utils/utils";
  82. import { onLoad, onUnload } from "@dcloudio/uni-app";
  83. import { login, loginCode, loginTime, wechatAppID,userBasicGetOpenId,userBasicGetPhoneNumber } from "@/utils/network/api.js";
  84. import { requestNew} from "@/utils/network/request.js";
  85. import { stringToJson } from "@/utils/network/encryption";
  86. import { useUserStore } from "@/stores/user";
  87. import { setItem } from "@/utils/storage";
  88. const userStore = useUserStore();
  89. const { fetchToken } = userStore;
  90. const state = reactive({
  91. checked: false, //是否勾选协议
  92. isPwdType: true, //是不是密码类型
  93. loginType: "code", //pwd-密码登录 code-验证码登录
  94. username: "", //用户名
  95. password: "", //密码
  96. code: "", //验证码
  97. back: 0, //从app扫码看协议过来 登录了 还需要回到手机号验证页面 0 是原本的登录 1 要回去的登录(从哪来回哪去) 2运维跳转过来得中转页
  98. params:{},
  99. items: [{
  100. value: '1',
  101. name: '个人',
  102. checked: 'true'
  103. },
  104. {
  105. value: '2',
  106. name: '单位',
  107. },
  108. ]
  109. });
  110. onLoad((option) => {
  111. if (option.back == 1) {
  112. state.back = option.back
  113. }
  114. if (option.back == 2) {
  115. state.back = option.back
  116. state.params = JSON.parse(decodeURIComponent(option.params))
  117. }
  118. uni.$on("login", (data) => {
  119. state.username = data.phone;
  120. });
  121. });
  122. onUnload(() => {
  123. uni.$off("login");
  124. });
  125. const checkboxChange = (e) => {
  126. console.log(e);
  127. state.checked = !state.checked;
  128. };
  129. const checkboxChangeLogin = (e) => {
  130. console.log(e);
  131. var values = e.detail.value;
  132. for (var i = 0; i < state.items.length;i++) {
  133. const item = state.items[i]
  134. if(values.includes(item.value)){
  135. state.items[i]['checked']=true
  136. }else{
  137. state.items[i]['checked']=false
  138. }
  139. }
  140. };
  141. const sure=()=>{
  142. }
  143. // 去协议页面
  144. const toRead = () => {
  145. navTo("/login/agreement")
  146. }
  147. /* 登录 */
  148. const doLogin = () => {
  149. if (!state.username) {
  150. msg("请输入手机号!");
  151. return;
  152. }
  153. if (state.loginType === "pwd" && !state.password) {
  154. msg("请输入密码!");
  155. return;
  156. }
  157. if (state.loginType === "code" && !state.code) {
  158. msg("请输入验证码!");
  159. return;
  160. }
  161. if (!checkStr(state.username, "mobile")) {
  162. msg("请输入正确的手机号!");
  163. return;
  164. }
  165. if (!state.checked) {
  166. msg("请勾选我已阅读并同意《平台用户服务隐私协议》");
  167. return;
  168. }
  169. //判断是验证码登录,还是账号密码登录
  170. if (state.loginType === "code") {
  171. reqLogin(loginCode, {
  172. mobile: state.username,
  173. code: state.code,
  174. loginTime: loginTime,
  175. });
  176. } else {
  177. reqLogin(login, {
  178. mobile: state.username,
  179. password: state.password,
  180. loginTime: loginTime,
  181. });
  182. }
  183. };
  184. /* 执行登录 */
  185. const reqLogin = (code : string, data : object) => {
  186. console.log(code, data);
  187. const options = {
  188. type: 2,
  189. data: data,
  190. method: "POST",
  191. showLoading: true,
  192. };
  193. requestNew(code, options).then((res) => {
  194. const result = res;
  195. console.log(result);
  196. console.log(typeof (result));
  197. fetchToken(result.code).then((data : any) => {
  198. console.log("登录", data);
  199. setItem('mobile', state.username)
  200. subscribeMessages();
  201. msg("登录成功!");
  202. uni.$emit("refreshOrder");
  203. if (state.back == 1) {
  204. uni.navigateBack({
  205. delta: 1
  206. })
  207. } else if (state.back == 2) {
  208. const params = encodeURIComponent(JSON.stringify(state.params))
  209. uni.redirectTo({
  210. url:`/subpackage/after-sale/transfer-page?params=${params}`
  211. })
  212. } else{
  213. uni.switchTab({
  214. url: '/pages/index/index'
  215. })
  216. }
  217. });
  218. });
  219. };
  220. const decryptPhoneNumber=(e)=>{
  221. console.log("e",e)
  222. }
  223. </script>
  224. <style lang="scss" scoped>
  225. .login-main {
  226. border-top: 1rpx solid #dcdcdc;
  227. padding: 22rpx 30rpx 140rpx;
  228. .logo {
  229. width: 260rpx;
  230. height: 160rpx;
  231. }
  232. .group {
  233. display: flex;
  234. align-items: center;
  235. }
  236. .title {
  237. font-size: 46rpx;
  238. color: #333333;
  239. margin-top: 30rpx;
  240. font-weight: 600;
  241. }
  242. .form {
  243. width: 100%;
  244. margin-top: 100rpx;
  245. .form-input {
  246. display: flex;
  247. flex-direction: row;
  248. align-items: center;
  249. height: 90rpx;
  250. border-bottom: 1rpx solid #dcdcdc;
  251. padding: 0rpx 12rpx;
  252. color: #333333;
  253. &:last-child {
  254. margin-top: 50rpx;
  255. }
  256. .input {
  257. flex: 1;
  258. padding-right: 48rpx;
  259. font-size: 28rpx;
  260. font-family: Microsoft YaHei;
  261. background-color: transparent;
  262. }
  263. .arror {
  264. width: 28rpx;
  265. height: 25rpx;
  266. margin-left: 16rpx;
  267. margin-right: 40rpx;
  268. }
  269. .eye {
  270. width: 48rpx;
  271. height: 48rpx;
  272. }
  273. }
  274. .form-placeholder {
  275. color: #999999;
  276. }
  277. }
  278. .btn {
  279. width: 100%;
  280. margin: 120rpx 40rpx 50rpx;
  281. }
  282. .agreement {
  283. font-size: 24rpx;
  284. display: flex;
  285. align-items: center;
  286. .txt-grey {
  287. color: #666666;
  288. }
  289. .txt-green {
  290. color: #00b38b;
  291. }
  292. :deep(.u-checkbox) {
  293. margin-right: -20rpx;
  294. }
  295. }
  296. .btns {
  297. width: 100%;
  298. margin-top: 125rpx;
  299. justify-content: space-around;
  300. padding: 0px 8rpx;
  301. .bg {
  302. width: 80rpx;
  303. height: 80rpx;
  304. border-radius: 50%;
  305. .img {
  306. width: 48rpx;
  307. height: 48rpx;
  308. }
  309. }
  310. .blue {
  311. background-color: #1d9cff;
  312. }
  313. .orange {
  314. background-color: #feb654;
  315. }
  316. .purple {
  317. background-color: #8060ff;
  318. }
  319. .label {
  320. font-size: 26rpx;
  321. color: #333333;
  322. margin-top: 30rpx;
  323. }
  324. }
  325. }
  326. .mask{
  327. width: 100%;
  328. height:100vh;
  329. background:rgba(0,0,0,0.63);
  330. position: fixed;
  331. left: 0;
  332. top: 0;
  333. right: 0;
  334. bottom: 0;
  335. z-index: 999;
  336. display: flex;
  337. align-items: center;
  338. justify-content: center;
  339. }
  340. </style>