login.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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({
  187. icon:'none',
  188. title: "登录成功",
  189. });
  190. uni.setStorageSync('AppToken',res.token);
  191. uni.setStorageSync('userId',res.user.userId);
  192. uni.setStorageSync('avatar',res.user.avatar);
  193. uni.setStorageSync('nickName',res.user.nickName);
  194. if(res.user.isWeixinAuth==0){
  195. that.wxAuthOpen()
  196. }
  197. else{
  198. uni.$emit('refreshLogin');
  199. uni.$emit('refreshIM');
  200. }
  201. }
  202. else{
  203. uni.showToast({
  204. icon:'none',
  205. title: "授权登录失败,请重新登录",
  206. });
  207. }
  208. })
  209. .catch(error => {
  210. console.log(error)
  211. uni.hideLoading();
  212. uni.showToast({
  213. icon:'none',
  214. title: "授权登录失败,请重新登录",
  215. });
  216. })
  217. }
  218. })
  219. })
  220. .catch(err => {})
  221. } else {
  222. uni.showToast({
  223. title: '已拒绝授权',
  224. icon: 'none',
  225. duration: 2000,
  226. })
  227. }
  228. },
  229. back() {
  230. uni.reLaunch({
  231. url: '/pages/index/index',
  232. animationType: 'pop-in',
  233. animationDuration: 100
  234. })
  235. }
  236. },
  237. }
  238. </script>
  239. <style lang="scss">
  240. .container {
  241. flex: 1;
  242. display: flex;
  243. flex-direction: column;
  244. justify-content: flex-start;
  245. position: relative;
  246. }
  247. .force-login-wrap {
  248. width: 100%;
  249. height: 100%;
  250. overflow: hidden;
  251. z-index: 11111;
  252. top: 0;
  253. .force-login__content {
  254. position: absolute;
  255. left: 50%;
  256. top: 40%;
  257. transform: translate(-50%, -50%);
  258. .logo{
  259. display: flex;
  260. flex-direction: column;
  261. justify-content: center;
  262. align-items: center;
  263. .logo-img{
  264. border: 4upx solid #FFFFFF;
  265. box-shadow: 0px 5px 15px 2px rgba(0,0,0,0.1);
  266. border-radius: 50%;
  267. width: 80px;
  268. height: 80px;
  269. image{
  270. border-radius: 50%;
  271. width: 100%;
  272. height: 100%;
  273. overflow: hidden;
  274. }
  275. }
  276. .title{
  277. margin-top: 20rpx;
  278. font-size: 35rpx;
  279. font-family: PingFang SC;
  280. font-weight: bold;
  281. color: #000;
  282. margin-bottom: 30rpx;
  283. }
  284. }
  285. .login-notice {
  286. font-size: 28rpx;
  287. font-family: PingFang SC;
  288. font-weight: 400;
  289. color: #000;
  290. line-height: 44rpx;
  291. width: 500rpx;
  292. text-align: center;
  293. margin-bottom: 80rpx;
  294. }
  295. .btns{
  296. position: relative;
  297. width: 630rpx;
  298. height: 80rpx;
  299. .author-btn{ z-index:100;
  300. position: absolute;
  301. width: 630rpx;
  302. height: 80rpx;
  303. background: linear-gradient(to right, #C39A58 0%, #E2C99E 100%);
  304. background: -moz-linear-gradient(to right, #C39A58 0%, #E2C99E 100%);
  305. // box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  306. border-radius: 40rpx;
  307. font-size: 30rpx;
  308. font-family: PingFang SC;
  309. font-weight: 500;
  310. color: rgba(255, 255, 255, 1);
  311. }
  312. }
  313. .author-btn{
  314. z-index:100;
  315. // position: absolute;
  316. width: 630rpx;
  317. height: 80rpx;
  318. background: linear-gradient(to right, #C39A58 0%, #E2C99E 100%);
  319. background: -moz-linear-gradient(to right, #C39A58 0%, #E2C99E 100%);
  320. // box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  321. border-radius: 40rpx;
  322. font-size: 30rpx;
  323. font-family: PingFang SC;
  324. font-weight: 500;
  325. color: rgba(255, 255, 255, 1);
  326. }
  327. .close-btn {
  328. width: 630rpx;
  329. height: 80rpx;
  330. margin-top: 30rpx;
  331. border-radius: 40rpx;
  332. border: 2rpx solid #C39A58;
  333. background: none;
  334. font-size: 30rpx;
  335. font-family: PingFang SC;
  336. font-weight: 500;
  337. color: #C39A58;
  338. }
  339. }
  340. }
  341. .tips{
  342. margin-top: 30rpx;
  343. display: flex;
  344. justify-content: center;
  345. align-items: center;
  346. font-size: 28rpx;
  347. color: #000;
  348. checkbox{
  349. }
  350. .btn{
  351. color: #C39A58;
  352. }
  353. }
  354. .wxAuth{
  355. border-radius: 30rpx;
  356. width: 100%;
  357. padding: 15rpx;
  358. display: flex;
  359. flex-direction: column;
  360. align-items: center;
  361. justify-content: center;
  362. background-color: #FFFFFF;
  363. .title{
  364. font-size: 32rpx;
  365. margin: 10rpx 0rpx;
  366. font-weight: bold;
  367. text-align: center;
  368. }
  369. .wx-box{
  370. width: 100%;
  371. padding: 0rpx 30rpx;
  372. }
  373. }
  374. </style>