index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <view class="permission">
  3. <Nav :leftShow='false' title="君子校园"></Nav>
  4. <view class="user-permission">
  5. <view class="head">
  6. <view class="head-button">
  7. <image src="@/static/img/logo/logo.png" class="head-img" mode=""></image>
  8. <view class="head-text">君子校园</view>
  9. </view>
  10. </view>
  11. <view class="hint-box">
  12. <view class="hint-title">该程序将获取以下授权:</view>
  13. <view class="hint-info">获取你的公开信息(昵称,头像等)</view>
  14. <view class="hint-info">获取你的小程序唯一标示用于账户授权登陆</view>
  15. </view>
  16. <view class="hint">
  17. <view class="hint-left-circle" @click.stop="isFlag = !isFlag">
  18. <view v-if="!isFlag" class="hint-circle"></view>
  19. <image v-else class="hint-img" src="@/static/img/common/y-select.png" mode=""></image>
  20. </view>
  21. <view class="hint-text-1" @click.stop="isFlag = !isFlag">我已阅读并同意</view>
  22. <view class="hint-text-2" @click="isPop = true;html = member_agreement">《用户服务》</view>
  23. <view class="hint-text-2" @click="isPop = true;html = privacy_protocol">《隐私协议》</view>
  24. </view>
  25. <view class="button">
  26. <view class="common permission-login" @click="login">微信授权登录</view>
  27. <view class="common permission-cancel" @click="noLogin">暂不登录</view>
  28. </view>
  29. </view>
  30. <view v-if="isPop" class="pop-view">
  31. <view class="pop-view-box">
  32. <view class="pop-info" v-html="html"></view>
  33. <view class="pop-botton">
  34. <view style="background-color: #3169FA;color: white;" class=" " @click="setCheck(1)">确定</view>
  35. <view style="color: #3169FA;" class="" @click="setCheck()">取消</view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import tools from "@/service/tools";
  43. import {
  44. appletLogin
  45. } from "@/api/member";
  46. import {
  47. getAgreement
  48. } from "@/api/common.js";
  49. export default {
  50. data() {
  51. return {
  52. isFlag: false,
  53. isAjax: false,
  54. from: {
  55. code: "",
  56. },
  57. isPop: false,
  58. html: '',
  59. member_agreement: '', //用户协议
  60. privacy_protocol: '', //隐私协议
  61. };
  62. },
  63. onLoad() {
  64. },
  65. mounted() {
  66. this.getPrivacyInfo()
  67. },
  68. methods: {
  69. getPrivacyInfo() {
  70. getAgreement().then((res) => {
  71. if (res.code === 1) {
  72. this.member_agreement = res.data.member_agreement;
  73. this.privacy_protocol = res.data.privacy_protocol;
  74. }
  75. })
  76. },
  77. setCheck(type) {
  78. if (type === 1) {
  79. this.isFlag = false
  80. }
  81. this.isPop = false
  82. },
  83. login() {
  84. if (!this.isFlag) {
  85. return tools.error("请先勾选协议");
  86. }
  87. if (this.isAjax) {
  88. return false;
  89. }
  90. this.isAjax = true;
  91. uni.login({
  92. provider: "weixin",
  93. success: (loginRes) => {
  94. this.from.code = loginRes.code;
  95. this.getUserInfo();
  96. },
  97. fail: (loginRes) => {
  98. this.isAjax = false;
  99. tools.error("获取授权信息失败");
  100. },
  101. });
  102. },
  103. noLogin() {
  104. uni.switchTab({
  105. url: "/pages/index/index",
  106. });
  107. },
  108. async getUserInfo() {
  109. const res = await appletLogin(this.from);
  110. if (res.code == 1) {
  111. uni.setStorageSync('token', res.data.token)
  112. uni.setStorageSync('m_id', res.data.m_id)
  113. tools.success("授权成功");
  114. setTimeout(() => {
  115. uni.switchTab({
  116. url: "/pages/index/index",
  117. });
  118. }, 1000);
  119. } else {
  120. this.isAjax = false;
  121. tools.error(res.msg);
  122. }
  123. },
  124. },
  125. };
  126. </script>
  127. <style scoped lang="scss">
  128. .permission {
  129. width: 100vw;
  130. height: 100vh;
  131. background-color: #fff;
  132. position: relative;
  133. .hint {
  134. margin-top: 20rpx;
  135. display: flex;
  136. height: 34rpx;
  137. .hint-left-circle {
  138. width: 32rpx;
  139. height: 32rpx;
  140. margin-right: 18rpx;
  141. .hint-circle {
  142. width: 30rpx;
  143. height: 30rpx;
  144. border-radius: 50%;
  145. background-color: #fff;
  146. border: 2rpx solid #D9D9D9;
  147. }
  148. .hint-img {
  149. width: 32rpx;
  150. height: 32rpx;
  151. border-radius: 50%;
  152. }
  153. }
  154. .hint-text-1,
  155. .hint-text-2 {
  156. font-size: 24rpx;
  157. font-weight: 400;
  158. }
  159. .hint-text-1 {
  160. color: #999999;
  161. }
  162. .hint-text-2 {
  163. color: #ED301D;
  164. }
  165. }
  166. .hint-box {
  167. margin-top: 140rpx;
  168. margin-bottom: 20rpx;
  169. .hint-title {
  170. font-size: 28rpx;
  171. }
  172. .hint-info {
  173. font-size: 24rpx;
  174. color: #6f6f6f;
  175. margin-top: 12rpx;
  176. }
  177. }
  178. .pop-view {
  179. width: 100%;
  180. height: 100vh;
  181. position: absolute;
  182. top: 0;
  183. left: 0;
  184. background: rgba(0, 0, 0, 0.5);
  185. .pop-view-box {
  186. display: flex;
  187. flex-direction: column;
  188. margin: 400rpx auto;
  189. width: 80vw;
  190. height: 50vh;
  191. overflow: scroll;
  192. background-color: #fff;
  193. border-radius: 10rpx;
  194. box-sizing: border-box;
  195. padding: 20rpx 40rpx;
  196. .pop-info {
  197. flex: 1;
  198. overflow: auto;
  199. }
  200. .pop-botton {
  201. display: flex;
  202. justify-content: space-between;
  203. margin-top: 20rpx;
  204. box-sizing: border-box;
  205. padding: 0 130rpx;
  206. view {
  207. width: 100rpx;
  208. height: 50rpx;
  209. line-height: 50rpx;
  210. text-align: center;
  211. font-size: 30rpx;
  212. border: 2rpx solid #3169FA;
  213. border-radius: 10rpx;
  214. margin: 0 10rpx;
  215. }
  216. }
  217. }
  218. }
  219. .user-permission {
  220. position: absolute;
  221. top: 40%;
  222. left: 50%;
  223. transform: translate(-50%, -50%);
  224. width: 100%;
  225. padding: 0 36rpx;
  226. box-sizing: border-box;
  227. .head {
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. button::after {
  232. border-color: #fff !important;
  233. }
  234. .head-button {
  235. background-color: #fff;
  236. padding: 0;
  237. }
  238. .head-text {
  239. text-align: center;
  240. margin-top: 16rpx;
  241. font-weight: 400;
  242. color: #333333;
  243. font-size: 28rpx;
  244. }
  245. .head-img {
  246. width: 120rpx;
  247. height: 120rpx;
  248. border-radius: 50%;
  249. margin: 0 auto;
  250. }
  251. }
  252. .user-name-view {
  253. display: flex;
  254. margin-top: 100rpx;
  255. .user-name {
  256. font-weight: 400;
  257. color: #333333;
  258. font-size: 32rpx;
  259. }
  260. .user-input {
  261. width: 568rpx;
  262. border-bottom: 1rpx solid #D9D9D9;
  263. font-size: 32rpx;
  264. padding-bottom: 16rpx;
  265. }
  266. }
  267. .button {
  268. margin-top: 60rpx;
  269. .common {
  270. width: 100%;
  271. height: 88rpx;
  272. line-height: 88rpx;
  273. text-align: center;
  274. border-radius: 200rpx;
  275. }
  276. .permission-login {
  277. background: #41ABF5;
  278. color: #fff;
  279. &:active {
  280. background-color: #41ABF5;
  281. }
  282. }
  283. .permission-cancel {
  284. margin-top: 40rpx;
  285. background: rgb(247, 247, 247);
  286. &:active {
  287. background-color: rgb(238, 238, 238);
  288. }
  289. }
  290. }
  291. }
  292. }
  293. </style>