login.vue 8.4 KB

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