login.vue 8.6 KB

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