index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view class="login">
  3. <capsule></capsule>
  4. <view class="login-container">
  5. <view class="login-tab">
  6. <view v-for="item in loginList" :key="item.id" :class="idx == item.id ? 'act' : ''"
  7. @click="changeIdx(item.id)">{{ item.title }}</view>
  8. </view>
  9. <view class="login-ipt">
  10. <view class="ipt-list">
  11. <tui-input placeholder="请输入您的账号" v-model="loginAccount.username" :inputBorder="true"
  12. :radius="16"></tui-input>
  13. <view class="password" v-show="idx == 0">
  14. <tui-input :type="!showIcon ? 'text' : 'password'" placeholder="请输入您的密码"
  15. v-model="loginAccount.password" :inputBorder="true" :radius="16">
  16. <template #right>
  17. <view v-if="showIcon">
  18. <tui-icon name="unseen" :size="26" @click="changeIcon(false)"></tui-icon>
  19. </view>
  20. <view v-else>
  21. <tui-icon name="seen" :size="26" @click="changeIcon(true)"></tui-icon>
  22. </view>
  23. </template>
  24. </tui-input>
  25. </view>
  26. <view class="code" v-show="idx == 1">
  27. <tui-input placeholder="请输入验证码" v-model="loginAccount.code" :inputBorder="true" :radius="16">
  28. <template #right>
  29. <tui-countdown-verify :successVal="successVal" @send="getVerify" color="#EF530E"
  30. borderColor="transparent" :size="28" :seconds="60"
  31. :resetVal="resetVal"></tui-countdown-verify>
  32. </template>
  33. </tui-input>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="login-protocol">
  38. <view class="protocal-conter">
  39. <view v-show="protocolTrue" @click="radioClick(false)">
  40. <tui-icon name="circle-selected" :size="32" unit="rpx" color="#EF530E"></tui-icon>
  41. </view>
  42. <view v-show="!protocolTrue" @click="radioClick(true)">
  43. <tui-icon name="circle" :size="32" unit="rpx"></tui-icon>
  44. </view>
  45. <view class="protocol-txt">
  46. <text :style="{ color: protocolTrue ? '#000' : '#CCCCCC' }">我已经阅读并同意</text>
  47. <text :style="{ color: protocolTrue ? '#EF530E' : '#FFD2BE' }">《用户协议及隐私政策》</text>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="btn-list">
  52. <view class="login-btn" @click="landing">登陆</view>
  53. <view class="register-btn">注册开店</view>
  54. </view>
  55. </view>
  56. <modal :showModal="modal" :promptList="promptList" @closeModal="closeModal" :showBtn="showBtn"></modal>
  57. </view>
  58. </template>
  59. <script>
  60. import { login, getCode } from '@/config/index.js'
  61. import JM from '@/utils/rsaEncrypt.js'
  62. export default {
  63. data() {
  64. return {
  65. idx: 0,
  66. loginList: [
  67. {
  68. id: 0,
  69. title: '密码登录'
  70. },
  71. {
  72. id: 1,
  73. title: '验证码登录'
  74. }
  75. ],
  76. loginAccount: {
  77. username: '',
  78. rememberMe: false,
  79. // 验证码
  80. code: '',
  81. // 密码
  82. password: '',
  83. },
  84. // 弹框显示
  85. modal: false,
  86. // 弹框显示的内容
  87. promptList: [],
  88. // 控制按钮显示
  89. showBtn: false,
  90. showIcon: true,
  91. // 控制是否同意协议
  92. protocolTrue: false,
  93. // 控制获取验证码成功
  94. successVal: 0,
  95. // 控制获取验证码失败
  96. resetVal: 0,
  97. }
  98. },
  99. methods: {
  100. // 关闭弹框
  101. closeModal() {
  102. this.modal = false
  103. },
  104. changeIdx(index) {
  105. this.idx = index
  106. },
  107. // 控制眼睛切换
  108. changeIcon(flag) {
  109. this.showIcon = flag
  110. },
  111. // 单选框修改
  112. radioClick(flag) {
  113. this.protocolTrue = flag
  114. },
  115. async getVerify() {
  116. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  117. if (!phoneCodeVerification.test(this.loginAccount.username)) {
  118. this.$showToast('请输入正确的账号!')
  119. this.resetVal++
  120. return
  121. }
  122. let res = await getCode({ phone: this.loginAccount.username });
  123. if (res.message == "") {
  124. this.successVal++
  125. } else {
  126. this.resetVal++
  127. }
  128. },
  129. // 登录
  130. landing() {
  131. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  132. if (!phoneCodeVerification.test(this.loginAccount.username)) {
  133. this.$showToast('请输入正确的账号!')
  134. this.resetVal++
  135. return
  136. }
  137. if (!this.protocolTrue) {
  138. this.$showToast('请勾选同意用户协议。')
  139. this.resetVal++
  140. return
  141. }
  142. if (this.idx == 0) {
  143. this.passwordLogin()
  144. }
  145. if (this.idx == 1) {
  146. this.codeLogin()
  147. }
  148. },
  149. // 密码登录的处理逻辑
  150. async passwordLogin() {
  151. let obj = {
  152. username: JM.encrypt(this.loginAccount.username),
  153. password: JM.encrypt(this.loginAccount.password),
  154. rememberMe: false
  155. }
  156. this.getLogin(obj)
  157. },
  158. // 验证码登录的处理逻辑
  159. async codeLogin() {
  160. if (this.loginAccount.code == '') {
  161. this.$showToast('请输入验证码')
  162. return
  163. }
  164. let codeObj = {
  165. username: JM.encrypt(this.loginAccount.username),
  166. code: JM.encrypt(this.loginAccount.code),
  167. rememberMe: false
  168. }
  169. this.getLogin(codeObj)
  170. },
  171. // 具体登陆接口调用
  172. async getLogin(data) {
  173. // 全局的加载状态显示
  174. this.$loading.show("登录中");
  175. try {
  176. let res = await login(data);
  177. if (res.code != '' && res.message == '用户未注册') {
  178. this.modal = true
  179. this.promptList = ['您的账户未注册店铺', '请重新输入']
  180. this.showBtn = true
  181. return
  182. } else if (res.code != '') {
  183. this.modal = true
  184. this.promptList = [res.message, '请重新输入']
  185. this.showBtn = false
  186. return
  187. }
  188. // 将数据存储到本地
  189. uni.setStorageSync("storage_info", res.data);
  190. uni.setStorageSync("storage_key", res.data.token);
  191. // 跳转到首页
  192. uni.switchTab({
  193. url: "/pages/tabbar/index/index",
  194. });
  195. } catch (error) {
  196. uni.showToast({
  197. title: error,
  198. duration: 1000000
  199. });
  200. } finally {
  201. this.$loading.hide();
  202. }
  203. }
  204. },
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. .login {
  209. width: 100vw;
  210. height: 100vh;
  211. .login-container {
  212. width: 100%;
  213. height: 100rpx;
  214. margin-top: 172rpx;
  215. padding: 0 68rpx;
  216. box-sizing: border-box;
  217. .login-tab {
  218. justify-content: space-between;
  219. font-size: 48rpx;
  220. padding-right: 70rpx;
  221. color: #999999;
  222. @include flex(space-between);
  223. margin-bottom: 60rpx;
  224. .act {
  225. color: #000;
  226. }
  227. }
  228. .login-ipt {
  229. width: 100%;
  230. .ipt-list {
  231. @include flex(center, column, 24rpx);
  232. .password {
  233. width: 100%;
  234. }
  235. .code {
  236. width: 100%;
  237. }
  238. }
  239. }
  240. .login-protocol {
  241. @include flex(center);
  242. margin-top: 34rpx;
  243. .protocal-conter {
  244. @include flex(center, null, 10rpx);
  245. .protocol-txt {
  246. font-size: 24rpx;
  247. }
  248. }
  249. }
  250. .btn-list {
  251. width: 100%;
  252. margin-top: 48rpx;
  253. @include flex(center, column, 32rpx);
  254. view {
  255. width: 100%;
  256. font-size: 36rpx;
  257. height: 96rpx;
  258. text-align: center;
  259. line-height: 96rpx;
  260. border-radius: 16rpx;
  261. }
  262. .login-btn {
  263. background-color: $primary-color;
  264. color: #fff;
  265. }
  266. .register-btn {
  267. border: 2rpx solid $primary-color;
  268. color: $primary-color;
  269. box-sizing: border-box;
  270. }
  271. }
  272. }
  273. }
  274. /* 弹框样式 */
  275. </style>