index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="login-container">
  3. <image src="http://wdklmall.oss-cn-shenzhen.aliyuncs.com/mallgoods/goods/C34A0AB308944EF9A3BB4135827924DF.png" class="background-img"></image>
  4. <view class="absolve-wrapper">
  5. <!-- <view class="logo"><image src="../../static/logo.png" class="logo-img"></image></view> -->
  6. <view class="flex-col items-center group_3 space-y-20">
  7. <text class="text_2 text_3">UU睡眠</text>
  8. <text class="font_1 text_2">AI时代,全家人的睡眠健康顾问</text>
  9. </view>
  10. <view class="login-main">
  11. <view class="input-wrapper">
  12. <i class="iconfont icon-phone icon"></i>
  13. <input placeholder="请输入账户名或手机号" v-model="userFrom.username" />
  14. </view>
  15. <view class="input-wrapper">
  16. <i class="iconfont icon-password icon"></i>
  17. <input v-if="isText" type="text" placeholder="请输入密码" v-model="userFrom.password" />
  18. <input v-else type="password" placeholder="请输入密码" v-model="userFrom.password" />
  19. <i class="iconfont eye" :class="isText ? 'icon-openEye' : 'icon-closeEye'" @click="isText = !isText"></i>
  20. </view>
  21. <button style="background: linear-gradient(90deg, rgba(44, 37, 247, 0.6) 0%, rgba(6, 21, 153, 1) 100%);" class="cu-btn round login-button lg cu-load" :class="{ loading: loading }" @click="getUserInfo">登录</button>
  22. <button v-if="haslogin.loginType === 'auto'" class="cu-btn round login-button lg cu-load" :class="{ loading: loading }" @click="loginByHasLogin">
  23. 微信快捷登录
  24. </button>
  25. <button v-if="haslogin.loginType === 'hand_movement'" class="cu-btn round login-button lg cu-load" :class="{ loading: loading }" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  26. 微信快捷登录
  27. </button>
  28. </view>
  29. <!-- <view class="other-login">-->
  30. <!-- <view class="other-text">第三方登录</view>-->
  31. <!-- <view class="login-list">-->
  32. <!-- <i class="iconfont icon-weixin other-item" @click="handleTest"></i>-->
  33. <!-- <i class="iconfont icon-qq other-item" @click="handleTest"></i>-->
  34. <!-- <i class="iconfont icon-weibo other-item" @click="handleTest"></i>-->
  35. <!-- </view>-->
  36. <!-- </view>-->
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import {mapActions} from 'vuex'
  42. import Storage from '@/utils/storage'
  43. import * as API_connect from '@/api/connect'
  44. import store from '@/store'
  45. export default {
  46. data() {
  47. return {
  48. loading: false,
  49. isText: false,
  50. userInfo: null,
  51. userFrom: {
  52. username: '',
  53. password: '',
  54. },
  55. haslogin: {
  56. loginType: 'hand_movement'
  57. },
  58. };
  59. },
  60. mounted() {
  61. if (!this.uuid) {
  62. this.uuid = Storage.getItem('uuid');
  63. }
  64. this.haslogin = Storage.getItem('haslogin')
  65. if (!this.haslogin) {
  66. uni.reLaunch({
  67. // url:'/pages/auth/auth'
  68. })
  69. return
  70. }
  71. const uInfo = Storage.getItem('myWeixinInfo')
  72. if (uInfo) {
  73. this.userInfo = uInfo
  74. }
  75. },
  76. methods: {
  77. getPhoneNumber(e) {
  78. console.log('e======', e)
  79. let _this = this
  80. let params = {
  81. encryptedData: e.detail.encryptedData,
  82. iv: e.detail.iv,
  83. uuid: _this.uuid,
  84. gender: _this.userInfo.gender,
  85. nickName: _this.userInfo.nickName
  86. };
  87. API_connect.accessMobile(params).then(result => {
  88. _this.resultEvent(result)
  89. }).catch(err=>{
  90. _this.removeAllItem()
  91. });
  92. },
  93. removeAllItem() {
  94. Storage.removeItem('login_result')
  95. Storage.removeItem('refresh_token')
  96. Storage.removeItem('access_token_timeout')
  97. Storage.removeItem('refresh_token_timeout')
  98. uni.showToast({
  99. title: '授权已失效,请重新授权!',
  100. icon: "none"
  101. })
  102. uni.reLaunch({
  103. url:'/pages/auth/auth'
  104. })
  105. },
  106. loginByHasLogin() {
  107. let _this = this
  108. if (this.haslogin && this.haslogin.uid) {
  109. API_connect.loginById({memberId: this.haslogin.uid, uuid: this.uuid}).then(result => {
  110. _this.resultEvent(result)
  111. }).catch(err=>{
  112. _this.removeAllItem()
  113. });
  114. } else {
  115. _this.removeAllItem()
  116. }
  117. },
  118. resultEvent(result) {
  119. const { access_token, access_token_timeout,refresh_token,refresh_token_timeout, uid } = result
  120. // 如果登录成功 存储token(access_token refresh_token) uid 获取用户数据
  121. if (access_token && refresh_token && uid) {
  122. Storage.setItem('haslogin', { uid: uid, loginType: 'auto'})
  123. store.dispatch('setAccessTokenAction', access_token)
  124. store.dispatch('setRefreshTokenAction', refresh_token)
  125. Storage.setItem('uid', uid);
  126. Storage.setItem('access_token_timeout',Math.round(new Date() / 1000)+access_token_timeout-60)
  127. Storage.setItem('refresh_token_timeout',Math.round(new Date() / 1000)+refresh_token_timeout-60)
  128. Storage.removeItem('myWeixinInfo')
  129. store.dispatch('getUserDataAction').then(()=>{
  130. uni.switchTab({
  131. url: '/pages/home/index'
  132. })
  133. })
  134. } else {
  135. this.removeAllItem()
  136. }
  137. },
  138. getUserInfo() {
  139. let that = this
  140. //测试账号,可以改成你自己的
  141. const form = this.userFrom
  142. if (!form.username || !form.password) {
  143. uni.showToast({
  144. title: '表单填写有误,请检查!',
  145. icon: 'none'
  146. })
  147. return false;
  148. }
  149. this.loading = true
  150. const login_type = 'account'
  151. this.login({ login_type, form })
  152. .then(() => {
  153. that.loading = false
  154. uni.switchTab({
  155. url: '/pages/home/index'
  156. })
  157. }).catch(err => {
  158. that.loading = false
  159. uni.showToast({
  160. title: err.data.message,
  161. icon: 'none'
  162. })
  163. })
  164. },
  165. ...mapActions({
  166. login: 'loginAction'
  167. })
  168. }
  169. };
  170. </script>
  171. <style lang="scss" scoped>
  172. .icon-password {
  173. color: #fff;
  174. }
  175. .icon-phone {
  176. color: #fff;
  177. }
  178. .eye {
  179. color: #fff;
  180. }
  181. .group_3 {
  182. padding: 4rem 0;
  183. .text_2 {
  184. opacity: 0.76;
  185. }
  186. .text_3 {
  187. color: #ffffff;
  188. font-size: 1.88rem;
  189. font-family: PingFangSC;
  190. line-height: 1.72rem;
  191. margin-top: 1rem;
  192. }
  193. .font_1 {
  194. font-size: 1.13rem;
  195. font-family: PingFangSC;
  196. line-height: 1.06rem;
  197. color: #ffffff;
  198. margin-top: 4rem;
  199. }
  200. }
  201. .login-container {
  202. width: 100%;
  203. height: 100vh;
  204. position: relative;
  205. overflow: hidden;
  206. // background: url(../../static/loginBg.png) no-repeat;
  207. // background-size: contain;
  208. .absolve-wrapper{
  209. position: absolute;
  210. top: 0;
  211. bottom: 0;
  212. right: 0;
  213. left: 0;
  214. width: 100%;
  215. height: 100%;
  216. }
  217. .background-img{
  218. width: 100%;
  219. height: 100%;
  220. }
  221. .logo {
  222. text-align: center;
  223. margin-top: 12%;
  224. .logo-img {
  225. width: 100px;
  226. height: 100px;
  227. }
  228. }
  229. .text-title {
  230. font-size: 48rpx;
  231. margin-top: 5%;
  232. text-align: center;
  233. color: #fffefe;
  234. }
  235. .login-main {
  236. box-sizing: border-box;
  237. position: absolute;
  238. top: 50%;
  239. transform: translateY(-50%);
  240. left: 10%;
  241. right: 10%;
  242. .input-wrapper {
  243. display: flex;
  244. align-items: center;
  245. margin-bottom: 30rpx;
  246. padding-bottom: 30rpx;
  247. border-bottom: 1px solid rgb(242, 242, 242);
  248. position: relative;
  249. .icon {
  250. margin-right: 10px;
  251. font-size: 16px;
  252. }
  253. .eye {
  254. float: right;
  255. position: absolute;
  256. right: 5px;
  257. font-size: 16px;
  258. }
  259. }
  260. .login-button {
  261. width: 100%;
  262. color: #fff;
  263. background: linear-gradient(90deg, rgba(5, 96, 232, 1) 0%, rgba(100, 158, 245, 1) 100%); letter-spacing: 2px;
  264. height: 45px;
  265. margin-top: 75rpx !important;
  266. }
  267. }
  268. .other-login {
  269. position: absolute;
  270. bottom: 5%;
  271. left: 10%;
  272. right: 10%;
  273. .other-text {
  274. text-align: center;
  275. color: rgba(0, 0, 0, 0.4);
  276. font-size: 28rpx;
  277. position: relative;
  278. &::before,
  279. &::after {
  280. position: absolute;
  281. background: rgba(0, 0, 0, 0.15);
  282. content: '';
  283. height: 1px;
  284. top: 50%;
  285. width: 100px;
  286. }
  287. &::before {
  288. left: 5px;
  289. }
  290. &::after {
  291. right: 5px;
  292. }
  293. }
  294. .login-list{
  295. margin-top: 15px;
  296. display: flex;
  297. justify-content: center;
  298. align-items: center;
  299. .other-item{
  300. flex: 1;
  301. font-size: 40px;
  302. text-align: center;
  303. &.icon-weixin{
  304. color: #17d874;
  305. }
  306. &.icon-qq{
  307. color: #32d6f5;
  308. }
  309. &.icon-weibo{
  310. color: rgb(234,93,92);
  311. }
  312. }
  313. }
  314. }
  315. /deep/ {
  316. .input-placeholder {
  317. color: rgb(194, 194, 194);
  318. font-size: 30rpx;
  319. }
  320. }
  321. }
  322. </style>