login.vue 8.6 KB

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