index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <view class="Home">
  3. <div class="Home-overlay"> </div>
  4. <div class="home-content">
  5. <view class="empty" :style="{height: statusBarHeight + 2 +'px'}"/>
  6. <view class="title">
  7. 中德智慧教育 <br/>
  8. 全球儿童思维教育专家
  9. </view>
  10. <view class="line"/>
  11. <view class="clause">
  12. <view class="clause-first">
  13. 内部系统,我们需要您授权以下信息
  14. </view>
  15. <view class="clause-seconed">
  16. <view class="dot" />
  17. 获取您的公开信息(昵称、头像等)
  18. </view>
  19. </view>
  20. <view class="phone-form">
  21. <view class="phone-form-phone">
  22. <input
  23. v-model="phone"
  24. :maxlength="11"
  25. type="tel"
  26. class="phone-form-phone-input"
  27. placeholder-style="color: #C7C7C7; font-size: 16px;"
  28. placeholder="手机号"
  29. />
  30. <view
  31. :class="['phone-form-phone-getCode', phoneIsTrue && 'phone-is-true']"
  32. @click.stop="getCode"
  33. >{{ state.codeMsg }}</view>
  34. </view>
  35. <input
  36. v-model="code"
  37. class="phone-form-code"
  38. placeholder-style="color: #C7C7C7; font-size: 16px;"
  39. placeholder="验证码"
  40. />
  41. <view :class="['phone-form-login', codeIsTrue && 'code-is-true']" @click="loginByCode">登录</view>
  42. </view>
  43. <view class="rule">
  44. 仅限中德智慧内部代理商使用
  45. </view>
  46. </div>
  47. <view class="logo">
  48. <image :src="staticPicture.logo" mode="aspectFit"/>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import { loginByCode, getCode } from '@/api/user.js'
  54. import { setLocalStorage } from '@/utils/wxTool.js'
  55. import { staticPicture } from '@/utils/global.js'
  56. import Tip from '@/utils/tip'
  57. export default {
  58. name: 'Home',
  59. computed: {
  60. statusBarHeight () {
  61. return this.$store.state.systemInfo.statusBarHeight
  62. },
  63. phoneIsTrue() {
  64. const reg =/^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  65. return reg.test(this.phone) && !this.state.codeDisabled
  66. },
  67. // 验证码格式是否正确
  68. codeIsTrue() {
  69. const reg =/^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  70. return reg.test(this.phone) && this.code && this.code.length === 4
  71. }
  72. },
  73. onReady () {
  74. },
  75. data () {
  76. return {
  77. code: '',
  78. staticPicture,
  79. loading: false,
  80. phone: undefined,
  81. state: {
  82. smsTime: 60, // 短信倒计时时间
  83. codeDisabled: false, // 短信是否禁用
  84. codeMsg: "获取验证码", // 短信按钮上的文字
  85. timer: null, // 短信上的定时器
  86. }
  87. }
  88. },
  89. methods: {
  90. // 获取验证码
  91. async getCode() {
  92. if(!this.phoneIsTrue) return
  93. this.getCodeStr();
  94. const {status, message} = await getCode(this.phone)
  95. if(status === 200) {
  96. await Tip.success('验证码发送成功')
  97. }else {
  98. Tip.error(message)
  99. }
  100. },
  101. // 获取短信按钮上的文字
  102. getCodeStr() {
  103. this.state.codeDisabled = true;
  104. // 验证码60秒倒计时
  105. if (!this.state.timer) {
  106. this.state.timer = setInterval(() => {
  107. if (this.state.smsTime > 0 && this.state.smsTime <= 60) {
  108. this.state.smsTime--;
  109. if (this.state.smsTime !== 0) {
  110. this.state.codeMsg = "重新发送(" + this.state.smsTime + ")";
  111. } else {
  112. clearInterval(this.state.timer);
  113. this.state.codeMsg = "获取验证码";
  114. this.state.smsTime = 60;
  115. this.state.timer = null;
  116. this.state.codeDisabled = false;
  117. }
  118. }
  119. }, 1000);
  120. }
  121. },
  122. async loginByCode() {
  123. if(!this.codeIsTrue) return
  124. const {status, message, data} = await loginByCode(this.phone, this.code)
  125. if(status === 200) {
  126. this.loading = false
  127. Tip.success('登录成功')
  128. setLocalStorage('token', data.token)
  129. this.$store.commit('set_userInfo', data)
  130. uni.reLaunch({
  131. url: '/pages/user/index'
  132. })
  133. } else {
  134. this.code = ''
  135. }
  136. },
  137. // 用户登录
  138. async Login (encryptedData, iv) {
  139. this.loading = true
  140. const {data, status} = await Login({encryptedData, iv, code: this.code})
  141. this.loading = false
  142. if (status === 200) {
  143. Tip.success('登录成功')
  144. setLocalStorage('token', data.token)
  145. this.$store.commit('set_userInfo', data)
  146. uni.reLaunch({
  147. url: '/pages/user/index'
  148. })
  149. } else {
  150. this.code = ''
  151. this.wxLogin()
  152. }
  153. }
  154. }
  155. }
  156. </script>
  157. <style scoped lang="less">
  158. .Home {
  159. width: 100vw;
  160. height: 100vh;
  161. background-color: #CFD0DE;
  162. padding: 12% 6% 34%;
  163. box-sizing: border-box;
  164. position: relative;
  165. .Home-overlay {
  166. position: absolute;
  167. top: 0;
  168. left: 0;
  169. right: 0;
  170. bottom: 0;
  171. background: rgba(38, 38, 58, 0.8);
  172. z-index: 3;
  173. }
  174. .home-content {
  175. position: absolute;
  176. z-index: 4;
  177. }
  178. .title {
  179. width: 600rpx;
  180. height: 160rpx;
  181. font-size: 60rpx;
  182. font-family: PingFangSC-Medium, PingFang SC;
  183. font-weight: 500;
  184. color: #FFFFFF;
  185. line-height: 80rpx;
  186. margin-bottom: 48rpx;
  187. }
  188. .line {
  189. width: 100rpx;
  190. height: 8rpx;
  191. background-color: #44CEB6;
  192. margin-bottom: 186rpx;
  193. }
  194. .clause {
  195. margin-bottom: 84rpx;
  196. .clause-first {
  197. font-size: 32rpx;
  198. font-family: PingFangSC-Regular, PingFang SC;
  199. font-weight: 400;
  200. color: #FFFFFF;
  201. }
  202. .clause-seconed {
  203. margin-top: 16rpx;
  204. font-size: 32rpx;
  205. font-family: PingFangSC-Regular, PingFang SC;
  206. font-weight: 400;
  207. color: rgba(255, 255, 255, 0.8);
  208. display: flex;
  209. align-items: center;
  210. .dot {
  211. width: 8rpx;
  212. height: 8rpx;
  213. border-radius: 50%;
  214. background-color: #fff;
  215. margin-right: 20rpx;
  216. }
  217. }
  218. }
  219. .auth-btn {
  220. width: 656rpx;
  221. height: 96rpx;
  222. background: #1677FF;
  223. border-radius: 200rpx;
  224. font-size: 32rpx;
  225. font-family: PingFangSC-Medium, PingFang SC;
  226. font-weight: 500;
  227. color: #FFFFFF;
  228. margin-left: -0%;
  229. display: flex;
  230. justify-content: center;
  231. align-items: center;
  232. }
  233. .rule {
  234. width: 100%;
  235. text-align: center;
  236. font-size: 24rpx;
  237. font-family: PingFangSC-Regular, PingFang SC;
  238. font-weight: 400;
  239. color: rgba(255, 255, 255, 0.8);
  240. text-align: center;
  241. margin-top: 20rpx;
  242. margin-bottom: 98rpx;
  243. }
  244. .logo {
  245. width: 100%;
  246. height: 266rpx;
  247. margin-left: -53rpx;
  248. position: fixed;
  249. bottom: 12%;
  250. z-index: 1;
  251. image {
  252. width: 42.96%;
  253. height: 100%;
  254. object-fit: cover;
  255. display: block;
  256. margin: 0 auto;
  257. }
  258. }
  259. }
  260. .phone-form {
  261. display: flex;
  262. flex-direction: column;
  263. align-items: center;
  264. margin-top: 76rpx;
  265. .phone-form-phone {
  266. display: flex;
  267. justify-content: space-between;
  268. align-items: center;
  269. padding: 8rpx;
  270. width: 622rpx;
  271. height: 96rpx;
  272. font-size: 32rpx;
  273. font-family: PingFangSC-Regular, PingFang SC;
  274. font-weight: 400;
  275. color: #333333;
  276. background: #F7F7F7;
  277. border-radius: 48rpx;
  278. box-sizing: border-box;
  279. overflow: hidden;
  280. .phone-form-phone-input {
  281. padding-left: 32rpx;
  282. width: 386rpx;
  283. height: 96rpx;
  284. line-height: 96rpx;
  285. }
  286. .phone-form-phone-getCode {
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. width: 220rpx;
  291. height: 80rpx;
  292. font-size: 28rpx;
  293. font-family: PingFangSC-Regular, PingFang SC;
  294. font-weight: 400;
  295. color: #FFFFFF;
  296. background: #D8D8D8;
  297. border-radius: 40rpx;
  298. }
  299. .phone-is-true {
  300. font-size: 28rpx;
  301. font-family: PingFangSC-Regular, PingFang SC;
  302. font-weight: 400;
  303. color: #FFFFFF;
  304. background: #193D9D;
  305. }
  306. }
  307. .phone-form-code {
  308. margin-top: 24rpx;
  309. padding-left: 40rpx;
  310. width: 622rpx;
  311. height: 96rpx;
  312. font-size: 32rpx;
  313. font-family: PingFangSC-Regular, PingFang SC;
  314. font-weight: 400;
  315. color: #333333;
  316. background: #F7F7F7;
  317. border-radius: 48rpx;
  318. box-sizing: border-box;
  319. }
  320. .phone-form-login {
  321. display: flex;
  322. justify-content: center;
  323. align-items: center;
  324. margin-top: 60rpx;
  325. width: 588rpx;
  326. height: 96rpx;
  327. font-size: 32rpx;
  328. font-family: PingFangSC-Regular, PingFang SC;
  329. font-weight: 400;
  330. color: #FFFFFF;
  331. background: #D9D9D9;
  332. border-radius: 48rpx;
  333. }
  334. .code-is-true {
  335. background: #193D9D;
  336. }
  337. }
  338. </style>