login.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="container">
  3. <view class="login-wrap">
  4. <view class="title">
  5. <text>HI,您好! 欢迎登录</text>
  6. </view>
  7. <view class="h-logo">
  8. <image class="logo-img" src="../../static/logo.png" mode=""></image>
  9. </view>
  10. <!-- <button class="login-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  11. <u-icon name="weixin-fill" color="green" size="26"></u-icon>
  12. 微信授权手机号登录
  13. </button> -->
  14. <button class="login-btn" @click="authWechatCodeLogin()">
  15. <u-icon name="weixin-fill" color="green" size="26"></u-icon>
  16. 授权微信登录
  17. </button>
  18. <view class="login-form">
  19. <view class="remember-acconut">
  20. <view class="remember-acconut-password">
  21. <u-radio-group
  22. v-model="radiovalue1"
  23. placement="column"
  24. @change="groupChange"
  25. >
  26. <u-radio
  27. :customStyle="{marginBottom: '8px'}"
  28. v-for="(item, index) in radiolist1"
  29. :key="index"
  30. :label="item.name"
  31. :name="item.name"
  32. @change="radioChange"
  33. >
  34. </u-radio>
  35. </u-radio-group>
  36. </view>
  37. <view @click="gotoRetieveAccount()" class="forget-acconut-password">
  38. 找回账号
  39. </view>
  40. </view>
  41. </view>
  42. <view class="login-form">
  43. <view class="agreement-content">
  44. <u-icon name="checkmark-circle-fill" color="#2979ff" size="20"></u-icon>
  45. <view class="agreement">
  46. <text>允许我们在必要的场景下合理使用你的相关信息,登录且同意</text>
  47. <text @click="gotoAgreement('1','会员协议')" class="text-color">《会员协议》、</text>
  48. <text @click="gotoAgreement('2','服务对象协议')" class="text-color">《服务对象协议》、</text>
  49. <text @click="gotoAgreement('3','服务对象协议')" class="text-color">《服务对象协议》</text>等内容
  50. </view>
  51. </view>
  52. </view>
  53. <!-- 判断微信是否绑定账号 -->
  54. <u-popup :show="show" :round="10" mode="center" >
  55. <view class="h-popo-content">
  56. <view class="h-img">
  57. <u-icon name="/static/login/u01.png" color="red" size="60"></u-icon>
  58. </view>
  59. <view class="text">
  60. <text>该微信未绑定账号</text>
  61. </view>
  62. <view class="h-btn-wrap">
  63. <view @click="cancelOption" class="h-left-btn">
  64. <text>取消</text>
  65. </view>
  66. <view @click="gotoBindAccount" class="h-right-btn">
  67. <text>去绑定</text>
  68. </view>
  69. </view>
  70. </view>
  71. </u-popup>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. export default {
  77. data() {
  78. return {
  79. show: false,
  80. userInfo: {
  81. username: 'uview-plus UI',
  82. password: '',
  83. openId: ''
  84. },
  85. // 基本案列数据
  86. radiolist1: [{
  87. name: '自动登录',
  88. disabled: true
  89. }],
  90. radiolist2: [{
  91. name: '允许我们在必要的场景下合理使用你的相关信息,登录且同意',
  92. disabled: true
  93. }],
  94. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  95. radiovalue1: '自动登录',
  96. radiovalue2: '22222',
  97. };
  98. },
  99. onLoad() {
  100. this.wechatCodeLogin();
  101. },
  102. methods: {
  103. // 去协议页面
  104. gotoAgreement(type,name){
  105. uni.navigateTo({
  106. url: '/myPages/TermsOfService/index?name='+name + '&type=' + type,
  107. })
  108. },
  109. // 取消操作
  110. cancelOption(){
  111. this.show = false;
  112. },
  113. // 去绑定账号
  114. gotoBindAccount(){
  115. this.show = false;
  116. uni.navigateTo({
  117. url: '/loginPages/login/bind-account',
  118. })
  119. },
  120. // 自动登录不成功,用户手动授权登录
  121. authWechatCodeLogin(){
  122. if(!this.userInfo.openId){
  123. this.show = true;
  124. }
  125. },
  126. // 微信小程序code自动登录
  127. wechatCodeLogin(){
  128. let that = this;
  129. wx.login({
  130. success(re) {
  131. that.$api.wxAuthLogin({code:re.code}).then(res=>{
  132. that.userInfo = res.data.data.userInfo
  133. uni.setStorageSync('userInfo',res.data.data.userInfo)
  134. uni.setStorageSync('accessToken',res.data.data.access_token)
  135. uni.setStorageSync('phoneIsBind',res.data.data.phoneIsBind)
  136. if (res.data.data.phoneIsBind){
  137. uni.switchTab({
  138. url: '/pages/index/index',
  139. })
  140. }else {
  141. that.show = true
  142. }
  143. })
  144. },
  145. })
  146. },
  147. getPhoneNumber (e) {
  148. uni.showToast({
  149. title: e.detail.code
  150. })
  151. console.log(e.detail.code) // 动态令牌
  152. console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
  153. console.log(e.detail.errno) // 错误码(失败时返回)
  154. },
  155. // 去找回账号页面
  156. gotoRetieveAccount(){
  157. uni.navigateTo({
  158. url: '/loginPages/login/retrieve-account',
  159. })
  160. },
  161. groupChange(n) {
  162. console.log('groupChange', n);
  163. },
  164. radioChange(n) {
  165. this.radiovalue1 = ""
  166. console.log('radioChange', n);
  167. },
  168. },
  169. };
  170. </script>
  171. <style lang="scss">
  172. page,body{
  173. background: #fff;
  174. }
  175. .container{
  176. width: 90%;
  177. margin: 0 auto;
  178. font-family: PingFangSC-Semibold, PingFang SC;
  179. .title{
  180. margin-top: 12px;
  181. width: 140px;
  182. font-size: 24px;
  183. font-weight: 600;
  184. color: #333333;
  185. line-height: 38px;
  186. }
  187. .h-logo{
  188. text-align: center;
  189. .logo-img{
  190. width: 160px;
  191. height: 122px;
  192. }
  193. }
  194. .login-wrap {
  195. .account{
  196. display: flex;
  197. }
  198. }
  199. .login-btn{
  200. text-align: center;
  201. color: #333;
  202. width: 70%;
  203. justify-content: center;
  204. margin: 0 auto;
  205. margin-top: 50px;
  206. height: 40px;
  207. line-height: 40px;
  208. border-radius: 8px;
  209. background: #FFE05C;
  210. border-radius: 21px;
  211. font-size: 14px;
  212. display: flex;
  213. .wechat-logo{
  214. height: 12px;
  215. width: 12px;
  216. }
  217. }
  218. .identifying-code{
  219. image{
  220. width: 80px;
  221. height: 30px;
  222. }
  223. }
  224. .remember-acconut{
  225. margin-top: 18px;
  226. display: flex;
  227. justify-content: space-between;
  228. color: #999999;
  229. .forget-acconut-password{
  230. color: rgb(96, 98, 102);
  231. font-size: 15px;
  232. line-height: 25px;
  233. margin-left: 30%;
  234. }
  235. }
  236. .agreement-content{
  237. margin-top: 18px;
  238. display: flex;
  239. // justify-content: space-between;
  240. color: #999999;
  241. align-items: center;
  242. .agreement{
  243. color: rgb(96, 98, 102);
  244. padding-left: 1px;
  245. font-size: 15px;
  246. .text-color{
  247. color: blue;
  248. }
  249. }
  250. }
  251. }
  252. .h-popo-content{
  253. height: 180px;
  254. padding: 12px;
  255. width: 300px;
  256. text-align: center;
  257. font-size: 14px;
  258. font-family: PingFangSC-Semibold, PingFang SC;
  259. .h-img{
  260. padding: 7px;
  261. display: flex;
  262. justify-content: center;
  263. }
  264. .h-text{
  265. margin-top: 12px;
  266. font-weight: 400;
  267. color: #666666;
  268. }
  269. .text{
  270. margin-top: 6px;
  271. font-weight: 400;
  272. color: #666666;
  273. }
  274. .h-btn-wrap{
  275. display: flex;
  276. justify-content: space-between;
  277. color: #333333;
  278. text-align: center;
  279. margin-top: 14px;
  280. .h-left-btn{
  281. height: 32px;
  282. line-height: 30px;
  283. background: #EEEEEE;
  284. width: 100px;
  285. text-align: center;
  286. border-radius: 16px;
  287. margin: 0 auto;
  288. }
  289. .h-right-btn{
  290. height: 32px;
  291. line-height: 30px;
  292. background: #FFE05C;
  293. width: 100px;
  294. border-radius: 16px;
  295. margin: 0 auto;
  296. }
  297. }
  298. }
  299. </style>