login.vue 8.4 KB

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