login.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <view class="container">
  3. <view class="head">
  4. <view class="head-image">
  5. <image :src="defaultavatarUrl" mode="" style="border-radius: 50%; width: 100%;height: 100%;"></image>
  6. </view>
  7. <view class="head-text">
  8. <p style="font-weight:bold;font-size: 35rpx;padding-bottom: 20rpx;">样叽</p>
  9. <p style="font-weight:bold;font-size: 35rpx;">YounGee</p>
  10. </view>
  11. </view>
  12. <view class="body">
  13. <button class="login-btn" @click="toggle('bottom')">微信授权</button>
  14. <button class="exit-btn" @click="exit()">取消登录</button>
  15. <view class="xieyi">
  16. <uni-data-checkbox multiple class="xieyi-btn" v-model="value" :localdata="range" @change="select">
  17. </uni-data-checkbox>
  18. <p class="xieyi-read">阅读并同意</p>
  19. <a class="xieyi-content" src="">《用户协议及隐私政策》</a>
  20. </view>
  21. </view>
  22. <view>
  23. <!-- 底部普通弹窗 -->
  24. <uni-popup ref="popup" background-color="#fff" @change="change" style="border-radius: 20rpx;">
  25. <view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }"
  26. style=" ">
  27. <view class=""
  28. style="width: 90%; margin: 0 auto; margin-top: 10% !important;margin-bottom: 10% !important;">
  29. <view class="Tasktext">
  30. <image :src="picture.task15" mode=""></image>
  31. <span>YoungGee申请使用</span>
  32. </view>
  33. <view class="">
  34. <h5>你的微信头像、昵称、地区及性别信息</h5>
  35. </view>
  36. <!-- 黑线 -->
  37. <view class="" style="border-bottom: 2rpx solid #C0C0C0;margin-top: 3%;margin-bottom: 3%;">
  38. </view>
  39. <view class="" style="display: flex;justify-content:space-around;">
  40. <image :src="picture.jpg7" mode="" style="width: 84rpx;height: 84rpx;border-radius: 10rpx;">
  41. </image>
  42. <view class="" style="width: 70%;">
  43. <p style='color: #000000; font-size: 28rpx;'>昵称</p>
  44. <p style='color: #999999; font-size: 24rpx;margin-top: 2%;'>微信个人信息</p>
  45. </view>
  46. <view class="" style="margin-top: 3%;">
  47. <image :src="picture.png6" mode="" style="width: 32rpx;height: 22rpx;"></image>
  48. </view>
  49. </view>
  50. <!-- 黑线 -->
  51. <view class="" style="border-bottom: 2rpx solid #C0C0C0;margin-top: 3%;margin-bottom: 3%;">
  52. </view>
  53. <view class="butto" style="margin-top: 3%;">
  54. <button class="mini-btn" size="mini" @tap="Reset"
  55. style="background-color: #F2F2F2;color:#20AC19 ; margin-right: 5%;">拒绝</button>
  56. <button class="mini-btn" size="mini" @tap="determine"
  57. style="background-color: #20AC19;color:#F2F2F2 ;margin-left: 5%;">允许</button>
  58. </view>
  59. </view>
  60. </view>
  61. </uni-popup>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. export default {
  67. data() {
  68. return {
  69. value: 0,
  70. range: [{
  71. "value": 1,
  72. "text": ""
  73. }],
  74. defaultavatarUrl: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/logoxin01.png',
  75. picture: {
  76. home8: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/home8.png',
  77. deng5: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/deng5.png',
  78. deng1: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/deng1.png',
  79. task15: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/task15.png',
  80. jpg7: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/7.jpg',
  81. png6: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/6.png'
  82. },
  83. type: 'center',
  84. nickname: '',
  85. gender: '',
  86. };
  87. },
  88. onLoad() {},
  89. methods: {
  90. select() {
  91. console.log(this.value)
  92. },
  93. //swiper滑动事件
  94. swiperChange: function(e) {
  95. this.swiper.index = e.detail.current;
  96. },
  97. //底部弹出层
  98. change(e) {
  99. console.log('当前模式:' + e.type + ',状态:' + e.show);
  100. },
  101. exit() {
  102. uni.navigateBack()
  103. },
  104. toggle(type) {
  105. //新版登录方式
  106. if (this.value.length !== 1) {
  107. uni.showToast({
  108. title: '请先阅读并同意协议',
  109. icon: 'none',
  110. duration: 2000
  111. });
  112. return;
  113. }
  114. uni.getUserProfile({
  115. desc: '登录',
  116. success: (res) => {
  117. //console.log(res);
  118. console.log(res)
  119. this.nickname = res.userInfo.nickName
  120. this.gender = res.userInfo.gender
  121. uni.setStorageSync('nickName', res.userInfo.nickName);
  122. uni.setStorageSync('avatarUrl', res.userInfo.avatarUrl);
  123. try {
  124. this.login();
  125. } catch (e) {}
  126. },
  127. fail: (res) => {
  128. console.log(res)
  129. }
  130. });
  131. },
  132. // 获取手机号
  133. onGetPhoneNumber(e) {
  134. if (e.detail.errMsg == "getPhoneNumber:fail user deny") { //用户决绝授权
  135. //拒绝授权后弹出一些提示
  136. } else {
  137. //允许授权
  138. console.log(e)
  139. this.$refs.popup.open('bottom')
  140. e.detail.encryptedData //加密的用户信息
  141. e.detail.iv //加密算法的初始向量 时要用到
  142. }
  143. },
  144. //登录
  145. login() {
  146. let _this = this;
  147. // 获取登录用户code
  148. uni.login({
  149. provider: 'weixin',
  150. onlyAuthorize: true,
  151. success: function(res) {
  152. // console.log(res);
  153. if (res.code) {
  154. let code = res.code;
  155. _this.$https.post('/youngee/c/p/login', {
  156. code: res.code, //wx.login 登录成功后的code
  157. gender: _this.gender,
  158. nickname: _this.nickname
  159. })
  160. .then(res => {
  161. if (res.data.code == -6) {
  162. uni.showToast({
  163. title: '您已被拉黑,请联系客服',
  164. icon: 'none',
  165. duration: 2000
  166. });
  167. } else {
  168. console.log(res)
  169. uni.setStorageSync('token', res.data.data.token);
  170. uni.setStorageSync('cookie', res.header['Set-Cookie']);
  171. uni.navigateBack()
  172. }
  173. })
  174. // uni.request({
  175. // url: 'http://localhost:8199/youngee/c/p/login', //演示地址,请以你的后端接口为准
  176. // method: 'POST',
  177. // data: {
  178. // code: res.code, //wx.login 登录成功后的code
  179. // gender: _this.gender,
  180. // nickname: _this.nickname
  181. // },
  182. // success: (cts) => {
  183. // if (cts.data.code == -6) {
  184. // uni.showToast({
  185. // title: '您已被拉黑,请联系客服',
  186. // icon: 'none',
  187. // duration: 2000
  188. // });
  189. // } else {
  190. // console.log(cts)
  191. // uni.setStorageSync('token', cts.data.data.token);
  192. // uni.setStorageSync('cookie', cts.header['Set-Cookie']);
  193. // uni.navigateBack()
  194. // }
  195. // }
  196. // });
  197. } else {
  198. uni.showToast({
  199. title: '登录失败!',
  200. duration: 2000
  201. });
  202. console.log('登录失败!' + res.errMsg)
  203. }
  204. }
  205. });
  206. },
  207. determine() {
  208. uni.showToast({
  209. title: "登录成功",
  210. duration: 1000,
  211. });
  212. this.$refs.popup.close()
  213. },
  214. xieyi() {
  215. console.log('进入协议')
  216. },
  217. }
  218. }
  219. </script>
  220. <style>
  221. .content {
  222. border-radius: 20rpx 20rpx 0 0 !important;
  223. }
  224. </style>
  225. <style lang="scss" scoped>
  226. .head {
  227. display: flex;
  228. align-items: center;
  229. /* 垂直居中 */
  230. height: 200rpx;
  231. margin-top: 30%;
  232. margin-bottom: 20%;
  233. }
  234. .head-image {
  235. display: inline-block;
  236. margin: 0 50rpx 0 150rpx;
  237. width: 160rpx;
  238. height: 160rpx;
  239. background-color: #F0D232;
  240. border-radius: 50%;
  241. }
  242. .login-btn {
  243. margin: 30rpx;
  244. font-size: 35rpx;
  245. background-color: #F0D232;
  246. border: none;
  247. border-radius: 0;
  248. }
  249. .exit-btn {
  250. margin: 30rpx;
  251. font-size: 35rpx;
  252. border: 1rpx solid #000000;
  253. border-radius: 0;
  254. }
  255. .xieyi {
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. }
  260. .xieyi-btn {
  261. width: 40rpx;
  262. display: inline-block;
  263. font-size: 25rpx;
  264. }
  265. .xieyi-content {
  266. display: inline-block;
  267. font-size: 25rpx;
  268. }
  269. .xieyi-read {
  270. display: inline-block;
  271. font-size: 25rpx;
  272. }
  273. /deep/ .content {
  274. border-radius: 20rpx 20rpx 0 0 !important;
  275. }
  276. .Tasktext {
  277. // padding-top: 5%;
  278. padding: 0 0 0 1%;
  279. height: 80rpx;
  280. }
  281. .Tasktext span {
  282. color: #333333;
  283. font-size: 40%;
  284. font-weight: 550;
  285. text-indent: 2em;
  286. }
  287. .TitleText1 p {
  288. color: #333333;
  289. font-size: 50%;
  290. }
  291. .Tasktext {
  292. // height: 70rpx;
  293. }
  294. .Tasktext image {
  295. vertical-align: middle;
  296. width: 50rpx;
  297. height: 50rpx;
  298. display: inline-block;
  299. padding-right: 14rpx;
  300. }
  301. .butto {
  302. text-align: center;
  303. }
  304. .mini-btn {
  305. height: 55rpx;
  306. width: 150rpx;
  307. line-height: 55rpx;
  308. margin: 30rpx;
  309. }
  310. .diagram {
  311. padding-top: 30%;
  312. }
  313. .but {
  314. width: 80%;
  315. height: 60rpx;
  316. background-color: #FFD700;
  317. border-radius: 30rpx;
  318. border: 6rpx solid #0C0A03;
  319. text-align: center;
  320. line-height: 60rpx;
  321. margin: 0 auto;
  322. position: relative;
  323. font-size: 30rpx;
  324. font-weight: 550;
  325. letter-spacing: 7px;
  326. }
  327. .but span {
  328. font-size: 30rpx;
  329. font-weight: 550;
  330. letter-spacing: 7px;
  331. }
  332. .bei {
  333. // position: relative;
  334. }
  335. .mark {
  336. position: absolute;
  337. width: 8rpx;
  338. height: 8rpx;
  339. border: 2rpx solid #0C0A03;
  340. border-radius: 20px;
  341. background-color: #1E90FF;
  342. }
  343. .butt {
  344. text-align: center;
  345. padding-top: 10rpx;
  346. }
  347. .butt span {
  348. font-size: 24rpx;
  349. color: #969696;
  350. }
  351. </style>