login.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <view class="verification">
  3. <navbar :config="config" backColor="#666"></navbar>
  4. <form @submit="formSubmit">
  5. <view class="content">
  6. <view class="password">
  7. <view class="left">
  8. 密码登录
  9. <text @click="goToForgetPass">忘记密码</text>
  10. </view>
  11. <view class="right" @click="goToverification">
  12. 验证码登录<text class="iconfont u-font24 u-999">&#xe6c7;</text>
  13. </view>
  14. </view>
  15. <view class="phone">
  16. <view class="number">
  17. 手机号
  18. </view>
  19. <input type="number" value="" name="phone" @input="onPhone" maxlength="11" placeholder="请输入手机号"
  20. placeholder-class="phone-login" />
  21. </view>
  22. <view class="passpwd">
  23. <view class="number">
  24. 密码登录
  25. </view>
  26. <input type="text" value="" name="pw" password="true" maxlength="11" @input="onPassword" placeholder="请输入登录密码"
  27. placeholder-class="password-login" />
  28. </view>
  29. <view class="agreement">
  30. <view class="whole">
  31. <view class="top" v-if="flag" @click="onFlag">
  32. <icon type="success" color="#FF0000" size="17"></icon>
  33. </view>
  34. <view class="top" v-else style="width: 30rpx;height: 30rpx;border-radius: 50%;border: #ccc solid 1rpx;"
  35. @click="onFlag"></view>
  36. </view>
  37. <view class="agree">
  38. 我已阅读并同意<text @click="goToAgreement">《会员注册协议》</text>
  39. </view>
  40. </view>
  41. <button class="login-button" form-type="submit">
  42. 登录
  43. </button>
  44. <view class="go-to-register" @click="goToregister">
  45. 去注册
  46. </view>
  47. </view>
  48. </form>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. appLogin,
  55. getAccountInfo
  56. } from "../../../api/login.js"
  57. export default {
  58. data() {
  59. return {
  60. config: {
  61. back: false, //false是tolbar页面 是则不写
  62. title: '用户登录',
  63. color: '#1A1A1A',
  64. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  65. backgroundColor: [1, "#fff"],
  66. statusBarFontColor: '#1A1A1A',
  67. },
  68. flag: false, //用户协议
  69. phone: "", //手机号
  70. password: "", //密码
  71. // isPhone:false,
  72. }
  73. },
  74. methods: {
  75. //忘记密码
  76. goToForgetPass() {
  77. uni.navigateTo({
  78. url: "../setup/forgetPass"
  79. })
  80. },
  81. //跳转用户注册协议
  82. goToAgreement() {
  83. uni.navigateTo({
  84. url: "./agreement"
  85. })
  86. },
  87. //验证码登录
  88. goToverification() {
  89. uni.redirectTo({
  90. url: "./verification"
  91. })
  92. },
  93. //去注册
  94. goToregister() {
  95. uni.redirectTo({
  96. url: "./register"
  97. })
  98. },
  99. //登录
  100. async formSubmit(e) {
  101. if (!this.phone) {
  102. this.$mUtil.toast("请输入手机号")
  103. return false
  104. }
  105. if (!this.password) {
  106. this.$mUtil.toast("请输入密码")
  107. return false
  108. }
  109. if (this.flag == false) {
  110. this.$mUtil.toast("请先同意协议")
  111. return false
  112. }
  113. if (!(this.phone.match(this.$mConfig.telRegex))) {
  114. this.$mUtil.toast("请输入正确的手机号")
  115. return false
  116. }
  117. let param = {
  118. mobile: this.phone,
  119. password: this.password,
  120. cid: uni.getStorageSync('cid')
  121. }
  122. let res = await this.$http.post(appLogin, param)
  123. if (res && res.code == 200) {
  124. if (res.data.code != 500) {
  125. this.$mUtil.toast("登录成功")
  126. uni.setStorageSync('apiToken', res.data.token);
  127. uni.setStorageSync("shop", res.data.shop);
  128. this.$http.get(getAccountInfo).then(res => {
  129. if (res && res.code == 200) {
  130. uni.setStorageSync("personal", res.data)
  131. }
  132. })
  133. setTimeout(function() {
  134. uni.navigateBack({
  135. delta: 1
  136. })
  137. }, 1000)
  138. } else {
  139. this.$mUtil.toast(res.data.msg)
  140. }
  141. }
  142. },
  143. //手机号
  144. onPhone(e) {
  145. this.phone = e.detail.value
  146. // if(this.phone.match(this.$mConfig.telRegex)){
  147. // this.isPhone=true
  148. // }else{
  149. // this.isPhone=false
  150. // }
  151. },
  152. //密码
  153. onPassword(e) {
  154. this.password = e.detail.value
  155. },
  156. //用户协议
  157. onFlag() {
  158. this.flag = !this.flag
  159. },
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. /deep/ .hx-navbar__content__main_center_txt {
  165. span {
  166. color: #fff;
  167. font-size: 36rpx;
  168. font-weight: 400;
  169. font-family: PingFang SC, PingFang SC-Regular;
  170. }
  171. }
  172. .phone-login {
  173. color: #CCCCCC;
  174. font-size: 28rpx;
  175. font-weight: 500;
  176. }
  177. .password-login {
  178. color: #CCCCCC;
  179. font-size: 28rpx;
  180. font-weight: 500;
  181. }
  182. .go-to-register {
  183. padding: 18rpx 0;
  184. color: #FA6138;
  185. font-size: 32rpx;
  186. font-weight: Regular;
  187. width: 100%;
  188. text-align: center;
  189. margin-top: 24rpx;
  190. border: 1rpx solid #3775F6;
  191. border-radius: 20rpx;
  192. }
  193. .login-button {
  194. width: 100%;
  195. text-align: center;
  196. margin-top: 70rpx;
  197. color: #ffffff;
  198. font-size: 32rpx;
  199. font-weight: Regular;
  200. background-color: #FA6138;
  201. border-radius: 20rpx;
  202. }
  203. .agreement {
  204. margin-top: 40rpx;
  205. display: flex;
  206. }
  207. .agree {
  208. font-size: 28rpx;
  209. color: #999999;
  210. font-weight: Regular;
  211. margin-left: 10rpx;
  212. text {
  213. color: #0047B1;
  214. }
  215. }
  216. .top {
  217. display: flex;
  218. align-items: center;
  219. }
  220. .choice {
  221. margin: 0 50rpx;
  222. display: flex;
  223. align-items: center;
  224. .whole {
  225. display: flex;
  226. align-items: center;
  227. }
  228. }
  229. .passpwd {
  230. display: flex;
  231. margin-top: 40rpx;
  232. padding-bottom: 32rpx;
  233. border-bottom: 1rpx solid #E6E6E6;
  234. .number {
  235. font-size: 28rpx;
  236. font-weight: 500;
  237. color: #333333;
  238. }
  239. input {
  240. flex: 1;
  241. margin-left: 40rpx;
  242. }
  243. }
  244. .phone {
  245. display: flex;
  246. align-items: center;
  247. margin-top: 40rpx;
  248. padding-bottom: 32rpx;
  249. border-bottom: 1rpx solid #e6e6e6;
  250. .number {
  251. font-size: 28rpx;
  252. color: #333333;
  253. font-weight: 500;
  254. }
  255. input {
  256. flex: 1;
  257. margin-left: 70rpx;
  258. }
  259. }
  260. .password {
  261. display: flex;
  262. .left {
  263. font-size: 38rpx;
  264. font-weight: Bold;
  265. color: #333333;
  266. line-height: 28rpx;
  267. flex: 1;
  268. text {
  269. font-size: 28rpx;
  270. color: #666666;
  271. font-weight: 400;
  272. margin-left: 20rpx;
  273. }
  274. }
  275. .right {
  276. color: #666666;
  277. font-size: 28rpx;
  278. font-weight: Regular;
  279. }
  280. }
  281. .content {
  282. margin: 80rpx 50rpx;
  283. }
  284. </style>