shouquan.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="containar">
  3. <view class="avatarUrl" style="text-align: center">
  4. <!-- <image src="../../static/index/shouquan.png" style="width: 180rpx;height: 180rpx;" class="refreshIcon"></image> -->
  5. <view style="color: rgba(30, 125, 251, 1); font-weight: 500">新糖宝</view>
  6. </view>
  7. <view class="btn" style="margin-top: 60px; height: 600rpx">
  8. <button v-if="qiehuan" @click="denglu" style="background-color: rgba(30, 125, 251, 0.8); color: #fff; width: 650rpx">微信登录</button>
  9. <button v-else open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" style="background-color: rgba(30, 125, 251, 0.8); width: 650rpx; color: #fff">
  10. 微信登录
  11. </button>
  12. <checkbox-group @change="checkboxChange" style="margin-top: 30rpx; margin-left: 50rpx">
  13. <checkbox color="rgba(30, 125, 251, 1)" style="transform: scale(0.6)" value="agree" :checked="check" shape="circle" />
  14. <text style="color: rgba(166, 166, 166, 1); font-size: 26rpx" bindtap="toprotocol">我已阅读并同意</text>
  15. <text style="color: rgba(30, 125, 251, 1); font-size: 26rpx" @click="toptong">《用户协议》</text>
  16. <text style="color: rgba(30, 125, 251, 1); font-size: 26rpx" @click="toptong">《隐私政策》</text>
  17. </checkbox-group>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. access_token: '',
  26. code: '',
  27. nickName: '',
  28. encryptedData: '',
  29. iv: '',
  30. avatarUrl: '',
  31. agree: '', //默认勾选状态
  32. check: false,
  33. qiehuan: true
  34. }
  35. },
  36. onLoad() {
  37. // this.shouquan()
  38. this.access_token = wx.getStorageSync('access_token')
  39. uni.login({
  40. provider: 'weixin',
  41. success: (res) => {
  42. // 获取用户信息
  43. uni.getUserInfo({
  44. provider: 'weixin',
  45. success: function (res) {
  46. console.log('res', res)
  47. }
  48. })
  49. console.log('res-login', res)
  50. //请求登录接口
  51. if (res.errMsg == 'login:ok') {
  52. }
  53. }
  54. })
  55. },
  56. methods: {
  57. //勾选协议
  58. checkboxChange(e) {
  59. console.log(e.detail.value)
  60. this.agree = e.detail.value[0]
  61. this.qiehuan = this.agree == undefined || this.agree == ''
  62. },
  63. denglu() {
  64. wx.showToast({
  65. title: '请先勾选用户协议',
  66. icon: 'none',
  67. duration: 2000
  68. })
  69. },
  70. //用户协议跳转
  71. toptong() {
  72. uni.navigateTo({
  73. url: '../../packageThree/pages/yonghuxieyi/yonghuxieyi'
  74. })
  75. },
  76. getPhoneNumber(e) {
  77. if (this.qiehuan) {
  78. wx.showToast({
  79. title: '请先勾选用户协议',
  80. icon: 'none',
  81. duration: 2000
  82. })
  83. } else {
  84. const that = this
  85. console.log(e, '信息') //在这里的e里会有code等信息
  86. let numberCode = e.detail.code //取出code
  87. that.numberCode = numberCode
  88. console.log(numberCode)
  89. this.$axios
  90. .get('/mp/user/userAuthorizedLogin', {
  91. params: {
  92. code: wx.getStorageSync('code'),
  93. iv: wx.getStorageSync('iv'),
  94. encryptedData: wx.getStorageSync('encryptedData'),
  95. numberCode: that.numberCode
  96. },
  97. headers: {
  98. Authorization: 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
  99. 'Blade-Auth': wx.getStorageSync('access_token'),
  100. 'Tenant-Id': '000000'
  101. }
  102. })
  103. .then((response) => {
  104. let res = response
  105. console.log(res)
  106. if (res.success) {
  107. var userId = res.data.userId
  108. wx.setStorageSync('userId', userId)
  109. var huanzheNichen = res.data.name
  110. wx.setStorageSync('huanzheNichen', huanzheNichen)
  111. var createTime = res.data.createTime
  112. wx.setStorageSync('createTime', createTime)
  113. uni.switchTab({
  114. url: '/pages/index/index'
  115. })
  116. } else {
  117. console.log('患者端授权登录失败')
  118. }
  119. })
  120. }
  121. },
  122. //授权
  123. shouquan() {
  124. this.$axios
  125. .post(
  126. `/blade-auth/oauth/token?password=ceb8447cc4ab78d2ec34cd9f11e4bed2&tenantId=000000&username=test`,
  127. {},
  128. {
  129. headers: {
  130. Authorization: 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
  131. }
  132. }
  133. )
  134. .then((res) => {
  135. console.log(res)
  136. var access_token = res.access_token
  137. this.access_token = res.access_token
  138. // localStorage.setItem('access_token',access_token)网页
  139. wx.setStorageSync('access_token', access_token) //小程序
  140. })
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. .containar {
  147. background: #fff;
  148. .avatarUrl {
  149. padding: 80rpx 0 40rpx;
  150. background: #fff;
  151. button {
  152. background: #fff;
  153. line-height: 80rpx;
  154. height: auto;
  155. width: auto;
  156. padding: 20rpx 30rpx;
  157. margin: 0;
  158. // display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. .refreshIcon {
  162. // width: 160rpx;
  163. // height: 160rpx;
  164. border-radius: 50%;
  165. }
  166. .jt {
  167. width: 14rpx;
  168. height: 28rpx;
  169. }
  170. }
  171. }
  172. .nickname {
  173. background: #fff;
  174. padding: 20rpx 30rpx 80rpx;
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. .weui-input {
  179. padding-left: 60rpx;
  180. }
  181. }
  182. .btn {
  183. width: 100%;
  184. .btn-sub {
  185. width: 670rpx;
  186. margin: 80rpx auto 0;
  187. height: 90rpx;
  188. background: rgba(30, 125, 251, 1);
  189. border-radius: 45rpx;
  190. line-height: 90rpx;
  191. text-align: center;
  192. font-size: 36rpx;
  193. color: #fff;
  194. }
  195. }
  196. }
  197. </style>