login.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <view class="content">
  3. <view class="force-login-wrap">
  4. <view class="force-login__content y-f">
  5. <view class="logo">
  6. <view class="logo-img">
  7. <image :src="imgPath+'/app/image/logo.png'"></image>
  8. </view>
  9. <view class="title">{{imgname}}</view>
  10. </view>
  11. <view class="login-notice">为了提供更优质的服务,请先登录</view>
  12. <view class="btns">
  13. <!-- <button
  14. class="author-btn"
  15. open-type="getPhoneNumber"
  16. @getphonenumber="phoneLogin" >微信一键登录</button> -->
  17. <!-- <button class="author-btn" v-if="isAgreement==false" @click="handleAgree()">微信一键登录</button> -->
  18. <button class="author-btn" @click="handleAgree()">微信一键登录</button>
  19. </view>
  20. <button class="close-btn" @tap="back">暂不登录</button>
  21. <view class="tips">
  22. <checkbox :checked="isAgreement" @click="handleAgreement()" />
  23. <view @click="handleAgreement()">您同意并接受</view>
  24. <view class="btn" @click="openContent('userRegister')">《用户协议》</view>
  25. <view class="btn" @click="openContent('userPrivacy')">《隐私保护》</view>
  26. </view>
  27. </view>
  28. </view>
  29. <!-- <u-popup bgColor="#f6f6f6" :safeAreaInsetBottom="false" :round="15" mode="bottom" :show="wxShow" @close="wxAuthClose" @open="wxAuthOpen">
  30. <view class="wxAuth">
  31. <view class="title">编辑头像和昵称</view>
  32. <wx-auth class="wx-box" @updateUser="updateUser()" ref="wxauth" ></wx-auth>
  33. </view>
  34. </u-popup> -->
  35. </view>
  36. </template>
  37. <script>
  38. import { wxLogin,loginByMp } from '@/api/user'
  39. // import {wxAuth} from '../components/wxAuth.vue';
  40. export default {
  41. // components:{
  42. // wxAuth
  43. // },
  44. data() {
  45. return {
  46. wxShow:false,
  47. isAgreement:false,
  48. code:null,
  49. }
  50. },
  51. computed: {
  52. imgPath() {
  53. return this.$store.state.imgpath
  54. },
  55. appid() {
  56. return this.$store.state.appid
  57. },
  58. imgname() {
  59. return this.$store.state.logoname
  60. },
  61. },
  62. // onLoad(option) {
  63. // uni.$on('refreshLogin', () => {
  64. // uni.navigateBack({
  65. // delta:1
  66. // })
  67. // })
  68. // },
  69. onLoad(option) {
  70. uni.$on('refreshLogin', () => {
  71. const pages = getCurrentPages(); // 获取当前页面栈
  72. if (pages.length > 1) {
  73. uni.navigateBack({ delta: 1 }); // 有上一页才返回
  74. } else {
  75. // 如果是首页,跳转到某个默认页面(如首页)
  76. uni.reLaunch({ url: '/pages/index/index' }); // 或者用 switchTab 如果是 tabBar 页面
  77. // 或者直接提示用户
  78. uni.showToast({ title: '已经是首页了', icon: 'none' });
  79. }
  80. });
  81. },
  82. onUnload() {
  83. },
  84. mounted() {
  85. },
  86. methods: {
  87. gologin(){
  88. var that=this;
  89. uni.showLoading({
  90. title:"处理中"
  91. })
  92. uni.login({
  93. provider: 'weixin',
  94. success: async loginRes => {
  95. console.log(loginRes)
  96. let code = loginRes.code // 获取开发code
  97. var tuiUserId=uni.getStorageSync('tuiUserId');
  98. loginByMp({
  99. code: code,
  100. tuiUserId:tuiUserId
  101. })
  102. .then( res => {
  103. uni.hideLoading();
  104. if(res.code==200){
  105. uni.showToast({
  106. icon:'none',
  107. title: "登录成功",
  108. });
  109. uni.setStorageSync('userHistoryApp',res.user.historyApp);
  110. uni.setStorageSync('AppToken',res.token);
  111. uni.setStorageSync('userId',res.user.userId);
  112. uni.setStorageSync('avatar',res.user.avatar);
  113. uni.setStorageSync('nickName',res.user.nickName);
  114. if(res.user.isWeixinAuth==0){
  115. that.wxAuthOpen()
  116. }
  117. else{
  118. uni.$emit('refreshLogin');
  119. uni.$emit('refreshIM');
  120. }
  121. }
  122. else{
  123. uni.showToast({
  124. icon:'none',
  125. title: "授权登录失败,请重新登录",
  126. });
  127. }
  128. })
  129. .catch(error => {
  130. console.log(error)
  131. uni.hideLoading();
  132. uni.showToast({
  133. icon:'none',
  134. title: "授权登录失败,请重新登录",
  135. });
  136. })
  137. }
  138. })
  139. },
  140. updateUser(){
  141. this.wxShow=false;
  142. uni.$emit('refreshLogin');
  143. uni.$emit('refreshIM');
  144. },
  145. wxAuthOpen(){
  146. this.wxShow=true;
  147. var that=this;
  148. setTimeout(function(){
  149. that.$refs.wxauth.getUserInfo();
  150. })
  151. },
  152. wxAuthClose(){
  153. this.wxShow=false;
  154. },
  155. handleAgree(){
  156. if(!this.isAgreement){
  157. uni.showToast({
  158. icon:'none',
  159. title: "请先同意协议后再登录",
  160. });
  161. return
  162. }
  163. this.gologin()
  164. },
  165. openContent(type){
  166. console.log(type)
  167. uni.navigateTo({
  168. url:"/pages_user/agreement?type="+type
  169. })
  170. },
  171. handleAgreement(){
  172. this.isAgreement=!this.isAgreement;
  173. },
  174. // 微信用户手机号登录
  175. phoneLogin(e) {
  176. var that=this;
  177. uni.showLoading({
  178. title:"处理中"
  179. })
  180. console.log(e)
  181. // if (e.detail.errMsg == 'getPhoneNumber:ok') {
  182. // this.$getProvider()
  183. // .then(provider => {
  184. // console.log('当前的环境商',provider)
  185. // if (!provider) {
  186. // reject()
  187. // }
  188. // // uni登录
  189. // uni.login({
  190. // provider: provider,
  191. // success: async loginRes => {
  192. // console.log(loginRes)
  193. // let code = loginRes.code // 获取开发code
  194. // var tuiUserId=uni.getStorageSync('tuiUserId');
  195. // wxLogin({
  196. // encryptedData: e.detail.encryptedData,
  197. // iv: e.detail.iv,
  198. // code: code,
  199. // tuiUserId:tuiUserId
  200. // })
  201. // .then( res => {
  202. // uni.hideLoading();
  203. // if(res.code==200){
  204. // uni.showToast({
  205. // icon:'none',
  206. // title: "登录成功",
  207. // });
  208. // uni.setStorageSync('userHistoryApp',res.user.historyApp);
  209. // uni.setStorageSync('AppToken',res.token);
  210. // uni.setStorageSync('userId',res.user.userId);
  211. // uni.setStorageSync('avatar',res.user.avatar);
  212. // uni.setStorageSync('nickName',res.user.nickName);
  213. // if(res.user.isWeixinAuth==0){
  214. // that.wxAuthOpen()
  215. // }
  216. // else{
  217. // uni.$emit('refreshLogin');
  218. // uni.$emit('refreshIM');
  219. // }
  220. // }
  221. // else{
  222. // uni.showToast({
  223. // icon:'none',
  224. // title: "授权登录失败,请重新登录",
  225. // });
  226. // }
  227. // })
  228. // .catch(error => {
  229. // console.log(error)
  230. // uni.hideLoading();
  231. // uni.showToast({
  232. // icon:'none',
  233. // title: "授权登录失败,请重新登录",
  234. // });
  235. // })
  236. // }
  237. // })
  238. // })
  239. // .catch(err => {})
  240. // } else {
  241. // uni.showToast({
  242. // title: '已拒绝授权',
  243. // icon: 'none',
  244. // duration: 2000,
  245. // })
  246. // }
  247. },
  248. back() {
  249. // uni.reLaunch({
  250. // url: '/pages/index/index',
  251. // animationType: 'pop-in',
  252. // animationDuration: 100
  253. // })
  254. uni.navigateBack({
  255. delta: 1
  256. });
  257. }
  258. },
  259. }
  260. </script>
  261. <style lang="scss">
  262. .container {
  263. flex: 1;
  264. display: flex;
  265. flex-direction: column;
  266. justify-content: flex-start;
  267. position: relative;
  268. }
  269. .force-login-wrap {
  270. width: 100%;
  271. height: 100%;
  272. overflow: hidden;
  273. z-index: 11111;
  274. top: 0;
  275. .force-login__content {
  276. position: absolute;
  277. left: 50%;
  278. top: 40%;
  279. transform: translate(-50%, -50%);
  280. .logo{
  281. display: flex;
  282. flex-direction: column;
  283. justify-content: center;
  284. align-items: center;
  285. .logo-img{
  286. border: 4upx solid #FFFFFF;
  287. box-shadow: 0px 5px 15px 2px rgba(0,0,0,0.1);
  288. border-radius: 50%;
  289. width: 80px;
  290. height: 80px;
  291. image{
  292. border-radius: 50%;
  293. width: 100%;
  294. height: 100%;
  295. overflow: hidden;
  296. }
  297. }
  298. .title{
  299. margin-top: 20rpx;
  300. font-size: 35rpx;
  301. font-family: PingFang SC;
  302. font-weight: bold;
  303. color: #000;
  304. margin-bottom: 30rpx;
  305. }
  306. }
  307. .login-notice {
  308. font-size: 28rpx;
  309. font-family: PingFang SC;
  310. font-weight: 400;
  311. color: #000;
  312. line-height: 44rpx;
  313. width: 500rpx;
  314. text-align: center;
  315. margin-bottom: 80rpx;
  316. }
  317. .btns{
  318. position: relative;
  319. width: 630rpx;
  320. height: 80rpx;
  321. .author-btn{ z-index:100;
  322. position: absolute;
  323. width: 630rpx;
  324. height: 80rpx;
  325. background: linear-gradient( to right, #2583EB 0%, #6dbae9 100%);
  326. background: -moz-linear-gradient(to right, #2583EB 0%, #6dbae9 100%);
  327. // box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  328. border-radius: 40rpx;
  329. font-size: 30rpx;
  330. font-family: PingFang SC;
  331. font-weight: 500;
  332. color: rgba(255, 255, 255, 1);
  333. }
  334. }
  335. .author-btn{
  336. z-index:100;
  337. // position: absolute;
  338. width: 630rpx;
  339. height: 80rpx;
  340. background: linear-gradient(to right, #2583EB 0%, #6dbae9 100%);
  341. background: -moz-linear-gradient(to right, #2583EB 0%, #6dbae9 100%);
  342. // box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  343. border-radius: 40rpx;
  344. font-size: 30rpx;
  345. font-family: PingFang SC;
  346. font-weight: 500;
  347. color: rgba(255, 255, 255, 1);
  348. }
  349. .close-btn {
  350. width: 630rpx;
  351. height: 80rpx;
  352. margin-top: 30rpx;
  353. border-radius: 40rpx;
  354. border: 2rpx solid #2583EB;
  355. background: none;
  356. font-size: 30rpx;
  357. font-family: PingFang SC;
  358. font-weight: 500;
  359. color: #2583EB;
  360. }
  361. }
  362. }
  363. .tips{
  364. margin-top: 30rpx;
  365. display: flex;
  366. justify-content: center;
  367. align-items: center;
  368. font-size: 28rpx;
  369. color: #000;
  370. checkbox{
  371. }
  372. .btn{
  373. color: #2583EB;
  374. }
  375. }
  376. .wxAuth{
  377. border-radius: 30rpx;
  378. width: 100%;
  379. padding: 15rpx;
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. justify-content: center;
  384. background-color: #FFFFFF;
  385. .title{
  386. font-size: 32rpx;
  387. margin: 10rpx 0rpx;
  388. font-weight: bold;
  389. text-align: center;
  390. }
  391. .wx-box{
  392. width: 100%;
  393. padding: 0rpx 30rpx;
  394. }
  395. }
  396. </style>