index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="authorize">
  4. <view class="pictrue">
  5. <image :src="logoUrl"></image>
  6. <view class="iconfont icon-guanbi4" @click='close'></view>
  7. </view>
  8. <view class="title">账号登录</view>
  9. <view class="info">
  10. <checkbox-group @change='ChangeIsDefault' v-if="agreement">
  11. <checkbox :checked="protocol ? true : false" />您已同意商城<text class="agree"
  12. @click="privacy('user')">《用户协议》</text>
  13. 与<text class="agree" @click="privacy('privacy')">《隐私协议》</text>
  14. </checkbox-group>
  15. <view v-else>
  16. 登录注册即同意商城
  17. <text class="agree" @click="privacy('user')">《用户协议》</text>与<text class="agree" @click="privacy('privacy')">《隐私协议》</text>
  18. </view>
  19. </view>
  20. <button hover-class="none" v-if="mp_is_new" @tap="userLogin"
  21. class="btn1">微信授权登录</button>
  22. <button v-else-if="canUseGetUserProfile && code" hover-class="none" @tap="getUserProfile"
  23. class="btn1">微信授权登录</button>
  24. <button v-else hover-class="none" open-type="getUserInfo" @getuserinfo="setUserInfo"
  25. class="btn1">微信授权登录</button>
  26. <!-- <button hover-class="none" @click="isUp = true" class="btn2 acea-row row-center-wrapper">手机一键登录</button> -->
  27. </view>
  28. <!-- <block v-if="isUp">
  29. <mobileLogin :isUp="isUp" @close="maskClose" :authKey="authKey" @wechatPhone="wechatPhone"></mobileLogin>
  30. </block> -->
  31. <block v-if="isPhoneBox">
  32. <routinePhone :logoUrl="logoUrl" :isPhoneBox="isPhoneBox" @close="bindPhoneClose" :authKey="authKey">
  33. </routinePhone>
  34. </block>
  35. <block>
  36. <editUserModal :isShow="isShow" @closeEdit="closeEdit" @editSuccess="editSuccess">
  37. </editUserModal>
  38. </block>
  39. <view class="mask" @click='close'></view>
  40. </view>
  41. </template>
  42. <script>
  43. const app = getApp();
  44. // import mobileLogin from '../loginMobile/index.vue';
  45. import routinePhone from '../loginMobile/routine_phone.vue';
  46. import editUserModal from '@/components/eidtUserModal/index.vue'
  47. import {
  48. getLogo,
  49. silenceAuth,
  50. wechatAuthV2,
  51. authLogin
  52. } from '@/api/public';
  53. import {
  54. LOGO_URL,
  55. EXPIRES_TIME,
  56. USER_INFO,
  57. STATE_R_KEY
  58. } from '@/config/cache';
  59. import {
  60. getUserInfo
  61. } from '@/api/user.js';
  62. import Routine from '@/libs/routine';
  63. import wechat from '@/libs/wechat';
  64. import colors from '@/mixins/color.js';
  65. export default {
  66. mixins:[colors],
  67. props: {
  68. isShowAuth: {
  69. type: Boolean,
  70. default: false
  71. }
  72. },
  73. data() {
  74. return {
  75. isShow: false,//判断获取用户头像是否出现
  76. isUp: false,
  77. phone: '',
  78. isPhoneBox: false,
  79. logoUrl: '',
  80. code: '',
  81. authKey: '',
  82. options: '',
  83. userInfo: {},
  84. codeNum: 0,
  85. canUseGetUserProfile: false,
  86. mp_is_new: this.$Cache.get('MP_VERSION_ISNEW') || false,
  87. agreement: 0,
  88. protocol: false
  89. };
  90. },
  91. components: {
  92. // mobileLogin,
  93. routinePhone,
  94. editUserModal
  95. },
  96. mounted(options) {
  97. if (uni.getUserProfile) {
  98. this.canUseGetUserProfile = true;
  99. }
  100. getLogo().then(res => {
  101. this.logoUrl = res.data.logo_url;
  102. this.agreement = res.data.store_user_agreement;
  103. });
  104. let that = this;
  105. // #ifdef MP
  106. Routine.getCode()
  107. .then(code => {
  108. this.code = code
  109. })
  110. // #endif
  111. },
  112. methods: {
  113. close(){
  114. this.$emit('authColse', false);
  115. },
  116. privacy(type) {
  117. uni.navigateTo({
  118. url: "/pages/users/privacy/index?type=" + type
  119. })
  120. },
  121. ChangeIsDefault(e) {
  122. this.$set(this, 'protocol', !this.protocol);
  123. },
  124. // 小程序 22.11.8日删除getUserProfile 接口获取用户昵称头像
  125. userLogin() {
  126. if (!this.protocol && this.agreement) {
  127. return this.$util.Tips({
  128. title: '请先阅读并同意协议'
  129. });
  130. }
  131. Routine.getCode()
  132. .then(code => {
  133. uni.showLoading({
  134. title: '正在登录中'
  135. });
  136. authLogin({
  137. code,
  138. spread_spid: app.globalData.spid,
  139. spread_code: app.globalData.code
  140. }).then(res => {
  141. if (res.data.key !== undefined && res.data.key) {
  142. uni.hideLoading();
  143. this.authKey = res.data.key;
  144. this.isPhoneBox = true;
  145. } else {
  146. uni.hideLoading();
  147. let time = res.data.expires_time - this.$Cache.time();
  148. this.$store.commit('LOGIN', {
  149. token: res.data.token,
  150. time: time
  151. });
  152. this.getUserInfo(res.data.store_user_avatar || 0)
  153. }
  154. }).catch(err => {
  155. uni.hideLoading();
  156. uni.showToast({
  157. title: err,
  158. icon: 'none',
  159. duration: 2000
  160. });
  161. })
  162. })
  163. .catch(err => {
  164. uni.hideLoading();
  165. uni.showToast({
  166. title: err,
  167. icon: 'none',
  168. duration: 2000
  169. });
  170. });
  171. },
  172. editSuccess() {
  173. this.isShow = false
  174. this.$emit('onLoadFun');
  175. },
  176. closeEdit() {
  177. this.isShow = false
  178. this.$emit('onLoadFun');
  179. this.$util.Tips({
  180. title: '登录成功',
  181. icon: 'success'
  182. });
  183. },
  184. // 弹窗关闭
  185. // maskClose(store_user_avatar) {
  186. // this.isUp = false;
  187. // if (store_user_avatar) {
  188. // this.$emit('onLoadFun');
  189. // }
  190. // },
  191. bindPhoneClose(data) {
  192. if (data.isStatus) {
  193. uni.hideLoading();
  194. this.isPhoneBox = false;
  195. if(data.store_user_avatar){
  196. this.isShow = true
  197. }else{
  198. this.$emit('onLoadFun');
  199. this.$util.Tips({
  200. title: '登录成功',
  201. icon: 'success'
  202. });
  203. }
  204. // this.getUserInfo(data.store_user_avatar)
  205. // this.$util.Tips({
  206. // title: '登录成功',
  207. // icon: 'success'
  208. // }, {
  209. // tab: 3
  210. // });
  211. } else {
  212. this.isPhoneBox = false;
  213. }
  214. },
  215. // #ifdef MP
  216. /**
  217. * 获取个人用户信息
  218. */
  219. getUserInfo: function(store_user_avatar) {
  220. let that = this;
  221. getUserInfo().then(res => {
  222. uni.hideLoading();
  223. that.userInfo = res.data;
  224. that.$store.commit('SETUID', res.data.uid);
  225. that.$store.commit('UPDATE_USERINFO', res.data);
  226. if(store_user_avatar){
  227. that.isShow = true
  228. }else{
  229. that.$emit('onLoadFun');
  230. that.$util.Tips({
  231. title: '登录成功',
  232. icon: 'success'
  233. });
  234. }
  235. });
  236. },
  237. setUserInfo(e) {
  238. if (!this.protocol && this.agreement) {
  239. return this.$util.Tips({
  240. title: '请先阅读并同意协议'
  241. });
  242. }
  243. this.close();
  244. uni.showLoading({
  245. title: '正在登录中'
  246. });
  247. Routine.getCode()
  248. .then(code => {
  249. this.getWxUser(code);
  250. })
  251. .catch(res => {
  252. uni.hideLoading();
  253. });
  254. },
  255. //小程序授权api替换 getUserInfo
  256. getUserProfile() {
  257. if (!this.protocol && this.agreement) {
  258. return this.$util.Tips({
  259. title: '请先阅读并同意协议'
  260. });
  261. }
  262. this.close();
  263. uni.showLoading({
  264. title: '正在登录中'
  265. });
  266. let self = this;
  267. Routine.getUserProfile()
  268. .then(res => {
  269. let userInfo = res.userInfo;
  270. userInfo.code = this.code;
  271. userInfo.spread_spid = app.globalData.spid || this.$Cache.get('spid'); //获取推广人ID
  272. userInfo.spread_code = app.globalData.code; //获取推广人分享二维码ID
  273. Routine.authUserInfo(userInfo)
  274. .then(res => {
  275. if (res.data.key !== undefined && res.data.key) {
  276. uni.hideLoading();
  277. self.authKey = res.data.key;
  278. self.isPhoneBox = true;
  279. } else {
  280. uni.hideLoading();
  281. let time = res.data.expires_time - self.$Cache.time();
  282. self.$store.commit('LOGIN', {
  283. token: res.data.token,
  284. time: time
  285. });
  286. this.getUserInfo()
  287. }
  288. })
  289. .catch(res => {
  290. uni.hideLoading();
  291. uni.showToast({
  292. title: res.msg,
  293. icon: 'none',
  294. duration: 2000
  295. });
  296. });
  297. })
  298. .catch(res => {
  299. uni.hideLoading();
  300. });
  301. },
  302. getWxUser(code) {
  303. let self = this;
  304. Routine.getUserInfo()
  305. .then(res => {
  306. let userInfo = res.userInfo;
  307. userInfo.code = code;
  308. userInfo.spread_spid = app.globalData.spid; //获取推广人ID
  309. userInfo.spread_code = app.globalData.code; //获取推广人分享二维码ID
  310. Routine.authUserInfo(userInfo)
  311. .then(res => {
  312. if (res.data.key !== undefined && res.data.key) {
  313. uni.hideLoading();
  314. self.authKey = res.data.key;
  315. self.isPhoneBox = true;
  316. } else {
  317. uni.hideLoading();
  318. let time = res.data.expires_time - self.$Cache.time();
  319. self.$store.commit('LOGIN', {
  320. token: res.data.token,
  321. time: time
  322. });
  323. self.$emit('onLoadFun');
  324. self.$util.Tips({
  325. title: res.msg,
  326. icon: 'success'
  327. });
  328. }
  329. })
  330. .catch(res => {
  331. uni.hideLoading();
  332. uni.showToast({
  333. title: res.msg,
  334. icon: 'none',
  335. duration: 2000
  336. });
  337. });
  338. })
  339. .catch(res => {
  340. uni.hideLoading();
  341. });
  342. },
  343. // #endif
  344. }
  345. };
  346. </script>
  347. <style lang="scss">
  348. .mask{
  349. z-index: 99;
  350. }
  351. .authorize{
  352. width: 100%;
  353. height: 560rpx;
  354. background-color: #fff;
  355. border-radius: 48rpx 48rpx 0 0;
  356. position: fixed;
  357. left: 0;
  358. bottom: 0;
  359. z-index: 667;
  360. padding-top: 50rpx;
  361. text-align: center;
  362. .pictrue{
  363. width: 152rpx;
  364. height: 152rpx;
  365. border-radius: 50%;
  366. margin: 0 auto;
  367. position: relative;
  368. image{
  369. width: 100%;
  370. height: 100%;
  371. border-radius: 50%;
  372. border:1px solid #eee;
  373. }
  374. .iconfont{
  375. position: absolute;
  376. width: 52rpx;
  377. height: 52rpx;
  378. background: #EEE;
  379. border-radius: 50%;
  380. color: #888;
  381. font-size: 30rpx;
  382. text-align: center;
  383. line-height: 52rpx;
  384. right: -267rpx;
  385. top: -20rpx;
  386. }
  387. }
  388. .title{
  389. margin-top: 28rpx;
  390. font-size: 36rpx;
  391. color: #333333;
  392. }
  393. .info{
  394. color: #9E9E9E;
  395. font-size: 28rpx;
  396. margin-top: 14rpx;
  397. .agree{
  398. color: #333;
  399. }
  400. }
  401. .btn1{
  402. width: 536rpx;
  403. height: 86rpx;
  404. border-radius: 43rpx;
  405. color: #fff;
  406. text-align: center;
  407. line-height: 86rpx;
  408. margin: 50rpx auto 0 auto;
  409. background-color: var(--view-theme);
  410. font-size: 30rpx;
  411. }
  412. .btn2{
  413. width: 536rpx;
  414. height: 86rpx;
  415. border-radius: 43rpx;
  416. border: 2rpx solid var(--view-theme);
  417. color: var(--view-theme);
  418. font-size: 30rpx;
  419. margin: 40rpx auto 0 auto;
  420. }
  421. }
  422. </style>