login copy.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view class="containers" style="min-height: 100vh;">
  3. <view class="header" style="width: 100vw;height: 122rpx">
  4. <image class="backFn" src="../../static/images/common/back.png" @click="$switchTab('/')"></image>
  5. </view>
  6. <view class="logoText">
  7. <view class="texts" style="font-weight: bold;">
  8. <view class="txt">欢迎来到</view>
  9. <view class="txt">团蜂材料网</view>
  10. </view>
  11. <view class="" style="margin-top: 48rpx;margin-left: -6rpx;">
  12. <text class="appTitle">年轻的材料生活元宇宙</text>
  13. </view>
  14. </view>
  15. <view class="login-form">
  16. <tui-form ref="refLoginForm" :show-message="false">
  17. <view>
  18. <tui-input
  19. v-model="loginQuery.phone" label="+ 86" type="number" padding="26upx 20upx 26upx 0"
  20. placeholder-style="color: #f3c1c4;font-size: 32upx;" label-color="#ffffff" border-color="#EA5B1D"
  21. placeholder="请输入手机号码" background-color="transparent" :border-top="false" color="#ffffff"
  22. style="border-bottom: 2upx solid #ffffff;"
  23. ></tui-input>
  24. </view>
  25. <view v-if="loginType === 'password'">
  26. <tui-input
  27. v-model="loginQuery.password" type="password" padding="26upx 20upx 26upx 0"
  28. placeholder-style="color: #f3c1c4;font-size: 32upx;" background-color="transparent" :border-top="false"
  29. border-color="#EA5B1D" label-color="#ffffff" placeholder="请输入密码" color="#ffffff"
  30. style="border-bottom: 2upx solid #ffffff;"
  31. >
  32. </tui-input>
  33. </view>
  34. <view v-if="loginType === 'verificationCode'">
  35. <tui-input
  36. v-model="loginQuery.verificationCode" padding="26upx 20upx 26upx 0"
  37. placeholder-style="color: #f3c1c4;font-size: 32upx;" background-color="transparent" :border-top="false"
  38. border-color="#EA5B1D" label-color="#ffffff" placeholder="请输入验证码" color="#ffffff"
  39. style="border-bottom: 2upx solid #ffffff;"
  40. >
  41. <template #right>
  42. <tui-countdown-verify
  43. v-if="loginType === 'verificationCode'" ref="refLoginVerify" width="188upx" height="48upx"
  44. border-width="0" text="获取验证码"
  45. :size="30" color="#dddddd" @send="handleSendVerify"
  46. ></tui-countdown-verify>
  47. </template>
  48. </tui-input>
  49. </view>
  50. </tui-form>
  51. </view>
  52. <view style="display: flex;flex-direction: column;justify-content: center;align-items: center;margin-top: 80upx;">
  53. <view style="text-align: center;">
  54. <tui-button
  55. type="white" width="640rpx" height="82rpx" :size="38"
  56. margin="40upx 0 0" shape="circle"
  57. style="font-weight: bold;color: #ea5b1d!important;" @click="handleLogin"
  58. >
  59. 登录
  60. </tui-button>
  61. </view>
  62. </view>
  63. <view style="margin-top: 120upx;display: flex;flex-direction: column;align-items: center;">
  64. <view style="display: flex;justify-content: space-around;white-space: nowrap;">
  65. <view style="display: flex;flex-direction: column;align-items: center;">
  66. <view style="width: fit-content;padding: 14upx;border: 1upx solid #ffffff;border-radius: 48upx;">
  67. <tui-icon name="friendadd-fill" color="#ffffff" :size="22" @click="go('/pages/login/register')"></tui-icon>
  68. </view>
  69. <view style="margin-top: 12upx;font-size: 26upx;color: #ffffff;">密码注册</view>
  70. </view>
  71. <view
  72. v-if="!(loginType === 'password')"
  73. style="display: flex;flex-direction: column;align-items: center;padding-left: 48upx;"
  74. >
  75. <view style="width: fit-content;padding: 14upx;border: 1upx solid #ffffff;border-radius: 48upx;">
  76. <tui-icon name="pwd" color="#ffffff" :size="22" @click="loginType = 'password'"></tui-icon>
  77. </view>
  78. <view style="margin-top: 12upx;font-size: 26upx;color: #ffffff;">密码登录</view>
  79. </view>
  80. <view
  81. v-if="!(loginType === 'verificationCode')"
  82. style="display: flex;flex-direction: column;align-items: center;padding-left: 48upx;"
  83. >
  84. <view style="width: fit-content;padding: 14upx;border: 1upx solid #ffffff;border-radius: 48upx;">
  85. <tui-icon name="mobile" color="#ffffff" :size="22" @click="loginType = 'verificationCode'"></tui-icon>
  86. </view>
  87. <view style="margin-top: 12upx;font-size: 26upx;color: #ffffff;">短信登录</view>
  88. </view>
  89. <!-- #ifdef MP-ALIPAY -->
  90. <view
  91. v-if="!(loginType === 'verificationCode')"
  92. style="display: flex;flex-direction: column;align-items: center;padding-left: 48upx;"
  93. >
  94. <view style="width: fit-content;padding: 14upx;border: 1upx solid #ffffff;border-radius: 48upx;">
  95. <tui-icon name="mobile" color="#ffffff" :size="22" @click="handleAliPayLogin"></tui-icon>
  96. </view>
  97. <view style="margin-top: 12upx;font-size: 26upx;color: #ffffff;">支付宝登录</view>
  98. </view>
  99. <!-- #endif -->
  100. <view
  101. v-if="($store.state.app.terminal === 3) || ($store.state.app.terminal === 2)"
  102. style="display: flex;flex-direction: column;align-items: center;padding-left: 48upx;"
  103. >
  104. <view style="width: fit-content;padding: 14upx;border: 1upx solid #ffffff;border-radius: 48upx;">
  105. <tui-icon name="wechat" color="#ffffff" :size="22" @click="handleWXLogin"></tui-icon>
  106. </view>
  107. <view style="margin-top: 12upx;font-size: 26upx;color: #ffffff;">微信登录</view>
  108. </view>
  109. </view>
  110. </view>
  111. </view>
  112. </template>
  113. <script>
  114. import { T_REDIRECT_TYPE, T_STORAGE_KEY } from '../../constant'
  115. import { getVerifyCodeApi } from '../../api/anotherTFInterface'
  116. import { CHANGE_IS_IN_MINIPROGRAM } from '../../store/modules/type'
  117. import { getUrlCode } from '../../utils'
  118. export default {
  119. name: 'Login',
  120. data() {
  121. return {
  122. loginType: 'verificationCode', // password,verificationCode
  123. loginQuery: {
  124. phone: '',
  125. verificationCode: '',
  126. password: ''
  127. }
  128. }
  129. },
  130. onLoad(options) {
  131. if (options.to) uni.setStorageSync(T_REDIRECT_TYPE, options.to)
  132. if (options.miniProgram) {
  133. this.$store.commit(`app/${CHANGE_IS_IN_MINIPROGRAM}`, !!options.miniProgram)
  134. }
  135. },
  136. onShow() {
  137. const userInfo = uni.getStorageSync(T_STORAGE_KEY)
  138. if (userInfo && userInfo.token) {
  139. uni.switchTab({
  140. url: '/'
  141. })
  142. } else if (this.$store.state.app.terminal === 3) {
  143. const code = getUrlCode().code
  144. if (code) this.handleWXLogin()
  145. }
  146. },
  147. methods: {
  148. // 获取验证码
  149. handleSendVerify() {
  150. if (!this.loginQuery.phone) {
  151. this.$refs.refLoginVerify.reset()
  152. return this.$showToast('请填写手机号')
  153. }
  154. if (!/^1[3-9]\d{9}$/.test(this.loginQuery.phone)) {
  155. this.$refs.refLoginVerify.reset()
  156. return this.$showToast('请输入正确的手机号')
  157. }
  158. getVerifyCodeApi({ phone: this.loginQuery.phone })
  159. .then((res) => {
  160. this.$refs.refLoginVerify.success()
  161. this.$showToast('发送成功,请注意查看手机短信')
  162. })
  163. .catch(() => {
  164. this.$refs.refLoginVerify.reset()
  165. })
  166. },
  167. // 点击登录
  168. handleLogin() {
  169. const validateRules = [ {
  170. name: 'phone',
  171. rule: ['required', 'isMobile'],
  172. msg: ['请输入手机号', '请输入正确的手机号']
  173. } ]
  174. let loginFilterQuery
  175. if (this.loginType === 'verificationCode') {
  176. validateRules.push({
  177. name: 'verificationCode',
  178. rule: ['required', 'isNum'],
  179. msg: [ '请输入验证码' ]
  180. })
  181. loginFilterQuery = {
  182. phone: this.loginQuery.phone,
  183. verificationCode: this.loginQuery.verificationCode
  184. }
  185. } else if (this.loginType === 'password') {
  186. validateRules.push({
  187. name: 'password',
  188. rule: ['required', 'isEnAndNo'],
  189. msg: ['请输入密码', '密码为8~20位英文和数字组合']
  190. })
  191. loginFilterQuery = {
  192. phone: this.loginQuery.phone,
  193. password: this.loginQuery.password
  194. }
  195. }
  196. this.$refs.refLoginForm
  197. .validate(this.loginQuery, validateRules)
  198. .then(() => {
  199. this.$store.dispatch('auth/phoneLoginRegisterAction', {
  200. isAfter: true,
  201. loginData: {
  202. type: 2, // 1注册,2登录
  203. ...loginFilterQuery
  204. }
  205. })
  206. })
  207. .catch((e) => {
  208. this.$showToast(JSON.stringify(e.errorMsg))
  209. })
  210. },
  211. async handleAliPayLogin() {
  212. await this.$store.dispatch('auth/aliPayLoginAction', { isAfter: true })
  213. },
  214. async handleWXLogin() {
  215. await this.$store.dispatch('auth/wxLoginAction', { isAfter: true })
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="less" scoped>
  221. .containers {
  222. display: flex;
  223. flex-direction: column;
  224. position: relative;
  225. box-sizing: border-box;
  226. padding-bottom: 66rpx;
  227. background-color: #EA5B1D;
  228. .backFn {
  229. padding: 30rpx 30rpx;
  230. width: 62rpx;
  231. height: 62rpx;
  232. }
  233. .logoText {
  234. width: 100vw;
  235. height: 280rpx;
  236. box-sizing: border-box;
  237. padding: 30rpx 0 0 56rpx;
  238. color: #ffffff;
  239. clear: both;
  240. .texts {
  241. /* font-style: oblique; */
  242. .txt {
  243. transform: skewX(-6deg);
  244. }
  245. line-height: 80rpx;
  246. font-size: 74rpx;
  247. letter-spacing: 6rpx;
  248. -webkit-box-reflect: below 2px -webkit-linear-gradient(top, rgba(250, 250, 250, 0), rgba(250, 250, 250, 0) 70%, rgba(255, 255, 255, 0.644));
  249. box-reflect: below 0px linear-gradient(top, rgba(250, 250, 250, 0), rgba(250, 250, 250, .05) 70%, rgba(250, 250, 250, 0.3));
  250. }
  251. }
  252. .appTitle {
  253. font-family: 思源黑体;
  254. font-size: 34rpx;
  255. font-weight: normal;
  256. line-height: 42rpx;
  257. color: rgba(255, 255, 255, 0.914);
  258. }
  259. .login-form {
  260. margin-top: 20upx;
  261. padding: 146rpx 48rpx 10rpx 48rpx;
  262. }
  263. }
  264. </style>