login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <view class="login">
  3. <view class="img">
  4. <image src="https://t9.9026.com/imgs/bg_1.jpg" mode="scaleToFill"></image>
  5. </view>
  6. <view class="title">
  7. <view class="line"></view>
  8. <view class="logintype"><text>登录方式</text></view>
  9. <view class="line"></view>
  10. </view>
  11. <view class="typebtn">
  12. <view class="item" @click="goYouyue">
  13. <image src="/static/icon/youyue.png" mode="scaleToFill"></image>
  14. <text>加入优悦会</text>
  15. </view>
  16. <view class="item" @click="getmsg">
  17. <image src="/static/icon/wechart.png" mode="scaleToFill"></image>
  18. <text>微信登录</text>
  19. <!-- <text v-if="isLoginOff">授权登录</text> -->
  20. </view>
  21. </view>
  22. <!-- <u-modal @close="closeMask" closeOnClickOverlay="true" :show="modal.show" :title="modal.title"
  23. :show-confirm-button="false">
  24. <view>
  25. <button class="avatar" open-type="chooseAvatar" @chooseavatar="handleChooseAvatar">
  26. <image class="user-avatar" style="height: 176rpx;width: 176rpx;border-radius: 50%;"
  27. :src="modal.avatar?modal.avatar:'/static/icon/avatar.png'" />
  28. </button>
  29. <input class="avatar" type="nickname" :value="modal.nickname" placeholder="填写昵称"
  30. @change="handleChangeNickname">
  31. <button class="confirm" @click="handleConfirmWechatUserInfo">提交</button>
  32. </view>
  33. </u-modal> -->
  34. <u-popup :show="modal.show" :round="10" mode="bottom" @close="close">
  35. <view class="popup-login">
  36. <view class="popup-login-top">
  37. <image style="width: 56rpx; height: 56rpx; margin-right: 20rpx; "
  38. src="https://t9.9026.com/imgs/loginLogo1.png" mode=""></image>
  39. <text>登录后体验更多功能</text>
  40. </view>
  41. <view class="popup-login-main">
  42. <button class="avatar" open-type="chooseAvatar" @chooseavatar="handleChooseAvatar">
  43. <image class="user-avatar" style="height: 176rpx;width: 176rpx;border-radius: 50%;"
  44. :src="modal.avatar?modal.avatar:'https://t9.9026.com/imgs/loginAvatar.png'" />
  45. </button>
  46. </view>
  47. <view class="popup-login-ipt">
  48. <input class="avatar" type="nickname" :value="modal.nickname" placeholder="输入昵称"
  49. @change="handleChangeNickname">
  50. </view>
  51. <view class="popup-login-btn" @click="handleConfirmWechatUserInfo">
  52. <button class="confirm">完成</button>
  53. </view>
  54. <view class="popup-login-text">
  55. <view style="display: flex;align-items: center;justify-content: center;">
  56. <text>登录即代表已阅读并同意</text>
  57. <view style="color: #FF6200;display: flex;align-items: center;justify-content: center;">
  58. <view @click="goAgreement">服务协议</view>
  59. <view @click="goPrivacy">、隐私协议</view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </u-popup>
  65. </view>
  66. </template>
  67. <script>
  68. export default {
  69. data() {
  70. return {
  71. imgBase64: '',
  72. isLoginOff: false,
  73. modal: {
  74. show: false,
  75. title: '用户信息获取',
  76. nickname: '',
  77. avatar: ''
  78. },
  79. code: '',
  80. encryptedData: '',
  81. iv: '',
  82. data: {}
  83. }
  84. },
  85. onLoad() {
  86. this.isLoginOff = this.$store.getters.userInfo
  87. },
  88. methods: {
  89. getPageUrl() {
  90. const pages = getCurrentPages();
  91. console.log(pages, '--------->pages')
  92. if (pages.length == 1) {
  93. const currentPage = pages[0];
  94. let pageUrl = `${currentPage.$page.fullPath}`;
  95. console.log('当前页面url1:', pageUrl);
  96. return pageUrl
  97. } else {
  98. const currentPage = pages[pages.length - 2];
  99. let pageUrl = `${currentPage.$page.fullPath}`;
  100. console.log('当前页面url2:', pageUrl);
  101. return pageUrl
  102. }
  103. },
  104. //服务协议
  105. goAgreement() {
  106. console.log(111);
  107. uni.navigateTo({
  108. url: '/pages/my/protocol/UserAgreement'
  109. })
  110. },
  111. //隐私协议
  112. goPrivacy() {
  113. console.log(222);
  114. uni.navigateTo({
  115. url: '/pages/my/protocol/PrivacyPolicy'
  116. })
  117. },
  118. //关闭遮罩层
  119. closeMask() {
  120. this.modal.show = false
  121. },
  122. close() {
  123. this.modal.show = false
  124. },
  125. //提交
  126. handleConfirmWechatUserInfo() {
  127. if (!this.modal.avatar) {
  128. this.$u.toast('请上传头像')
  129. return
  130. }
  131. if (!this.modal.nickname) {
  132. this.$u.toast('请填写昵称')
  133. return
  134. }
  135. this.$loading('数据提交中...')
  136. this.$api.my.update({
  137. avatar: this.modal.avatar,
  138. nickname: this.modal.nickname
  139. }).then(res => {
  140. this.$hideLoading()
  141. this.$store.dispatch('user/info', res.data)
  142. this.modal.show = false
  143. //获取登录页前地址
  144. let pages = this.getPageUrl()
  145. if (pages != '/pages/login/login') {
  146. uni.reLaunch({
  147. url: pages,
  148. })
  149. } else {
  150. uni.switchTab({
  151. url: '/pages/my/my'
  152. })
  153. }
  154. })
  155. },
  156. handleGetWechatUserInfo() {
  157. this.modal.show = true
  158. },
  159. // 获取头像
  160. handleChooseAvatar({
  161. detail
  162. }) {
  163. let _this = this
  164. // this.modal.avatar = detail.avatarUrl
  165. uni.getFileSystemManager().readFile({
  166. filePath: detail.avatarUrl, // 选择图片返回的相对路径
  167. encoding: 'base64', // 编码格式
  168. success: res => { // 成功的回调
  169. uni.uploadFile({
  170. url: _this.$setting.BASE_URL + '/v1/user/uploadFile',
  171. // filePath: 'data:image/png;base64,' + res.data,
  172. filePath: detail.avatarUrl,
  173. name: 'file',
  174. success({
  175. data
  176. }) {
  177. const res = JSON.parse(data)
  178. const {
  179. url
  180. } = res.data
  181. _this.modal.avatar = url
  182. console.log('-->data', _this.modal.avatar)
  183. }
  184. })
  185. // this.modal.avatar = detail.avatarUrl
  186. // console.log('data:image/png;base64,' + res.data)
  187. }
  188. })
  189. },
  190. //获取昵称
  191. handleChangeNickname(res) {
  192. this.modal.nickname = res.detail.value
  193. },
  194. // 加入优悦会
  195. goYouyue() {
  196. uni.navigateTo({
  197. url: '/pages/login/youyue'
  198. })
  199. },
  200. getCode() {
  201. return new Promise((resolve, reject) => {
  202. uni.getUserInfo({
  203. success: loginRes => {
  204. this.data.encryptData = loginRes.encryptedData,
  205. this.data.iv = loginRes.iv
  206. resolve(this.data)
  207. }
  208. })
  209. })
  210. },
  211. //获取微信登录的code码
  212. getmsg() {
  213. uni.login({
  214. provider: uni.$u.platform,
  215. success: res => {
  216. this.getCode().then((data) => {
  217. const params = {
  218. code: res.code,
  219. iv: data.iv,
  220. encryptData: data.encryptData
  221. }
  222. console.log(params);
  223. this.$api.my.myLogin(params).then(res => {
  224. if (res.code == 0) {
  225. let {
  226. token
  227. } = res.data
  228. this.handleGetWechatUserInfo()
  229. // this.handleConfirmWechatUserInfo()
  230. this.$store.dispatch('user/token', token)
  231. } else {
  232. uni.showToast({
  233. icon: 'none',
  234. title: res.msg
  235. })
  236. }
  237. })
  238. })
  239. }
  240. })
  241. },
  242. }
  243. }
  244. </script>
  245. <style lang="scss" scoped>
  246. $pageColor:#F9F9F9;
  247. $bgColor:#FFFFFF;
  248. .login {
  249. height: 100%;
  250. background: $bgColor;
  251. box-sizing: border-box;
  252. }
  253. .userinfo {
  254. position: absolute;
  255. top: 38rpx;
  256. left: 200rpx;
  257. .unlogin {
  258. width: 220rpx;
  259. font-size: 44rpx;
  260. font-family: PingFang-SC-Heavy, PingFang-SC;
  261. font-weight: 500;
  262. color: #FFFFFF;
  263. display: block;
  264. margin-top: 20rpx;
  265. }
  266. .username {
  267. width: 184rpx;
  268. height: 44rpx;
  269. font-size: 44rpx;
  270. font-family: PingFang-SC-Heavy, PingFang-SC;
  271. font-weight: 500;
  272. color: #FFFFFF;
  273. line-height: 44rpx;
  274. display: block;
  275. margin-bottom: 24rpx;
  276. }
  277. .userId {
  278. font-size: 32rpx;
  279. font-family: PingFang-SC-Medium, PingFang-SC;
  280. font-weight: 400;
  281. color: #FFFFFF;
  282. line-height: 32rpx;
  283. }
  284. }
  285. .img {
  286. image {
  287. width: 100vw;
  288. height: 910rpx;
  289. }
  290. }
  291. .title {
  292. height: 40rpx;
  293. width: 690rpx;
  294. // margin-top: 168rpx;
  295. margin-left: 30rpx;
  296. margin-bottom: 72rpx;
  297. display: flex;
  298. align-items: center;
  299. justify-content: space-between;
  300. .line {
  301. width: 240rpx;
  302. height: 2rpx;
  303. background: #EDEDED;
  304. border-radius: 1rpx;
  305. }
  306. .logintype {
  307. position: relative;
  308. top: -8rpx;
  309. text {
  310. font-size: 28rpx;
  311. font-family: PingFang-SC-Medium, PingFang-SC;
  312. font-weight: 500;
  313. color: #333333;
  314. }
  315. }
  316. }
  317. .typebtn {
  318. display: flex;
  319. align-items: center;
  320. justify-content: space-around;
  321. .item {
  322. width: 140rpx;
  323. height: 156rpx;
  324. display: flex;
  325. flex-direction: column;
  326. align-items: center;
  327. justify-content: center;
  328. image {
  329. width: 104rpx;
  330. height: 104rpx;
  331. margin-bottom: 12rpx;
  332. }
  333. text {
  334. display: block;
  335. font-size: 28rpx;
  336. font-family: PingFang-SC-Medium, PingFang-SC;
  337. font-weight: 500;
  338. color: #666666;
  339. }
  340. }
  341. }
  342. //登录弹框
  343. .popup-login {
  344. width: 100%;
  345. height: 750rpx;
  346. background: #FFFFFF;
  347. box-shadow: 0rpx -10rpx 32rpx 0px rgba(0, 0, 0, 0.04);
  348. border-radius: 16rpx 16rpx 0px 0px;
  349. padding: 40rpx 64rpx 92rpx;
  350. .popup-login-top {
  351. display: flex;
  352. align-items: center;
  353. justify-content: flex-start;
  354. font-size: 30rpx;
  355. font-weight: bold;
  356. color: #000000;
  357. }
  358. .popup-login-main {
  359. width: 100%;
  360. display: flex;
  361. align-items: center;
  362. justify-content: center;
  363. margin-top: 62rpx;
  364. .avatar {
  365. width: 176rpx;
  366. height: 176rpx;
  367. border-radius: 50%;
  368. border: 0;
  369. background: transparent;
  370. &::after {
  371. border: none;
  372. }
  373. .user-avatar {
  374. object-fit: cover;
  375. object-position: center;
  376. }
  377. }
  378. }
  379. .popup-login-ipt {
  380. width: 100%;
  381. height: 88rpx;
  382. background: #F6F6F6;
  383. border-radius: 44rpx;
  384. display: flex;
  385. align-items: center;
  386. justify-content: center;
  387. margin-top: 48rpx;
  388. .avatar {
  389. width: 100%;
  390. height: 100%;
  391. text-align: center;
  392. font-size: 28rpx;
  393. font-weight: bold;
  394. color: #999999;
  395. }
  396. }
  397. .popup-login-btn {
  398. width: 100%;
  399. height: 88rpx;
  400. background: #1AAC1B;
  401. border-radius: 38rpx;
  402. display: flex;
  403. align-items: center;
  404. justify-content: center;
  405. margin-top: 32rpx;
  406. .confirm {
  407. border: 0;
  408. background: transparent;
  409. font-size: 28rpx;
  410. font-weight: bold;
  411. color: #FFFFFF;
  412. &::after {
  413. border: none;
  414. }
  415. }
  416. }
  417. .popup-login-text {
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. margin-top: 32rpx;
  422. font-weight: bold;
  423. color: #999999;
  424. font-size: 22rpx;
  425. }
  426. }
  427. </style>