login.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <!-- 蓝色登录页面2 -->
  2. <template>
  3. <view>
  4. <u-toast ref="uToast"/>
  5. <view class="img-a">
  6. <view class="t-b">
  7. 您好,
  8. <br/>
  9. 欢迎使用 开源字节
  10. </view>
  11. </view>
  12. <view class="login-view">
  13. <view class="t-login">
  14. <form class="cl">
  15. <view class="t-a">
  16. <text class="txt">手机号</text>
  17. <input v-model="username" maxlength="11" name="phone" placeholder="请输入您的手机号" type="number"/>
  18. </view>
  19. <view class="t-a">
  20. <text class="txt">密码</text>
  21. <input v-model="password" maxlength="18" name="code" placeholder="请输入您的密码" type="password"/>
  22. </view>
  23. <button @tap="login()">登 录</button>
  24. <view class="reg" @tap="reg()">短信登录</view>
  25. </form>
  26. </view>
  27. </view>
  28. <!-- #ifdef MP-WEIXIN -->
  29. <view class="buttom">
  30. <button class="clearBtn" open-type="getPhoneNumber" @getphonenumber="weChatLogin">
  31. <view class="loginType">
  32. <view class="item">
  33. <view class="icon">
  34. <u-icon color="rgb(83,194,64)" name="weixin-fill" size="60"></u-icon>
  35. </view>
  36. 微信
  37. </view>
  38. </view>
  39. </button>
  40. <!-- <view class="hint">
  41. 登录代表同意
  42. <text class="link">开源字节用户协议、隐私政策,</text>
  43. 并授权使用您的账号信息(如昵称、头像、收获地址)以便您统一管理
  44. </view> -->
  45. </view>
  46. <!-- #endif -->
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. // username: '',
  54. // password: '',
  55. username: '18720989281',
  56. password: '123456',
  57. }
  58. },
  59. // onLoad() {
  60. // // 在页面中定义激励视频广告
  61. // let videoAd = null
  62. // // 在页面onLoad回调事件中创建激励视频广告实例
  63. // if (wx.createRewardedVideoAd) {
  64. // videoAd = wx.createRewardedVideoAd({
  65. // adUnitId: 'adunit-8cd5789a01a51891'
  66. // })
  67. // videoAd.onLoad(() => {})
  68. // videoAd.onError((err) => {})
  69. // videoAd.onClose((res) => {})
  70. // }
  71. // // 用户触发广告后,显示激励视频广告
  72. // if (videoAd) {
  73. // videoAd.show().catch(() => {
  74. // // 失败重试
  75. // videoAd.load()
  76. // .then(() => videoAd.show())
  77. // .catch(err => {
  78. // console.log('激励视频 广告显示失败')
  79. // })
  80. // })
  81. // }
  82. // },
  83. methods: {
  84. login() {
  85. if (!this.$u.test.mobile(this.username)) {
  86. return this.$refs.uToast.show({
  87. title: '手机号不正确',
  88. type: 'warning',
  89. })
  90. }
  91. if (!this.password) {
  92. return this.$refs.uToast.show({
  93. title: '密码不能为空',
  94. type: 'warning',
  95. })
  96. }
  97. // 登录json参数,不同于表单参数
  98. let url = "/api/thirdLogin";
  99. this.$u.post(url, {
  100. username: this.username,
  101. password: this.password
  102. }).then(data => {
  103. // 登录成功初始化token与用户信息
  104. this.$u.vuex('vuex_token', data.token);
  105. this.$u.vuex('vuex_user', data.loginUser);
  106. uni.switchTab({
  107. url: '/pages/index/index'
  108. })
  109. });
  110. },
  111. weChatLogin(e) {
  112. let code = e.detail.code;
  113. if (code) {
  114. uni.showLoading({title: "登录中....", mask: true})
  115. let url = "/api/miniWxApi/getPhoneNum?code=" + code;
  116. this.$u.get(url).then(res => {
  117. let phoneNum = res.phoneNum
  118. let weChatUrl = "/api/weChatLogin";
  119. this.$u.post(weChatUrl, {
  120. username: phoneNum,
  121. code: code
  122. }).then(data => {
  123. uni.hideLoading();
  124. // 登录成功初始化token与用户信息
  125. this.$u.vuex('vuex_token', data.token);
  126. this.$u.vuex('vuex_user', data.loginUser);
  127. uni.switchTab({
  128. url: '/pages/index/index'
  129. })
  130. });
  131. });
  132. } else {
  133. this.$mytip.toast('登录失败')
  134. }
  135. },
  136. reg() {
  137. this.$u.route({
  138. url: 'pages/login/account'
  139. })
  140. }
  141. }
  142. };
  143. </script>
  144. <style>
  145. page {
  146. background-color: #ffffff;
  147. }
  148. </style>
  149. <style lang="scss" scoped>
  150. .txt {
  151. font-size: 32 rpx;
  152. font-weight: bold;
  153. color: #333333;
  154. }
  155. .img-a {
  156. width: 100%;
  157. height: 450 rpx;
  158. background-image: url(https://zhoukaiwen.com/img/loginImg/head.png);
  159. background-size: 100%;
  160. }
  161. .reg {
  162. font-size: 28 rpx;
  163. color: #fff;
  164. height: 90 rpx;
  165. line-height: 90 rpx;
  166. border-radius: 50 rpx;
  167. font-weight: bold;
  168. background: #f5f6fa;
  169. color: #000000;
  170. text-align: center;
  171. margin-top: 30 rpx;
  172. }
  173. .login-view {
  174. width: 100%;
  175. position: relative;
  176. margin-top: -120rpx;
  177. background-color: #ffffff;
  178. border-radius: 8% 8% 0% 0;
  179. }
  180. .t-login {
  181. width: 600 rpx;
  182. margin: 0 auto;
  183. font-size: 28 rpx;
  184. padding-top: 80 rpx;
  185. }
  186. .t-login button {
  187. font-size: 28 rpx;
  188. background: #2796f2;
  189. color: #fff;
  190. height: 90 rpx;
  191. line-height: 90 rpx;
  192. border-radius: 50 rpx;
  193. font-weight: bold;
  194. }
  195. .t-login input {
  196. height: 90 rpx;
  197. line-height: 90 rpx;
  198. margin-bottom: 50 rpx;
  199. border-bottom: 1px solid #e9e9e9;
  200. font-size: 28 rpx;
  201. }
  202. .t-login .t-a {
  203. position: relative;
  204. }
  205. .t-b {
  206. text-align: left;
  207. font-size: 42 rpx;
  208. color: #ffffff;
  209. padding: 130 rpx 0 0 70 rpx;
  210. font-weight: bold;
  211. line-height: 70 rpx;
  212. }
  213. .t-login .t-c {
  214. position: absolute;
  215. right: 22 rpx;
  216. top: 22 rpx;
  217. background: #5677fc;
  218. color: #fff;
  219. font-size: 24 rpx;
  220. border-radius: 50 rpx;
  221. height: 50 rpx;
  222. line-height: 50 rpx;
  223. padding: 0 25 rpx;
  224. }
  225. .t-login .t-d {
  226. text-align: center;
  227. color: #999;
  228. margin: 80 rpx 0;
  229. }
  230. .t-login .t-e {
  231. text-align: center;
  232. width: 250 rpx;
  233. margin: 80 rpx auto 0;
  234. }
  235. .t-login .t-g {
  236. float: left;
  237. width: 50%;
  238. }
  239. .t-login .t-e image {
  240. width: 50 rpx;
  241. height: 50 rpx;
  242. }
  243. .t-login .t-f {
  244. text-align: center;
  245. margin: 150 rpx 0 0 0;
  246. color: #666;
  247. }
  248. .t-login .t-f text {
  249. margin-left: 20 rpx;
  250. color: #aaaaaa;
  251. font-size: 27 rpx;
  252. }
  253. .t-login .uni-input-placeholder {
  254. color: #aeaeae;
  255. }
  256. .cl {
  257. zoom: 1;
  258. }
  259. .cl:after {
  260. clear: both;
  261. display: block;
  262. visibility: hidden;
  263. height: 0;
  264. content: '\20';
  265. }
  266. .buttom {
  267. .loginType {
  268. display: flex;
  269. padding: 140 rpx 0;
  270. justify-content: center;
  271. .item {
  272. display: flex;
  273. flex-direction: column;
  274. align-items: center;
  275. color: $u-tips-color;
  276. font-size: 22 rpx;
  277. }
  278. }
  279. .hint {
  280. position: absolute;
  281. bottom: 0;
  282. padding: 20 rpx 40 rpx;
  283. font-size: 20 rpx;
  284. color: $u-tips-color;
  285. .link {
  286. color: #2979ff;
  287. }
  288. }
  289. }
  290. .clearBtn {
  291. margin: 0;
  292. padding: 0;
  293. line-height: 1;
  294. background-color: #FFFFFF;
  295. }
  296. .clearBtn::after {
  297. position: unset !important;
  298. border: unset;
  299. }
  300. </style>