index.vue 10.0 KB

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