login.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="app">
  3. <!-- logo -->
  4. <view class="header">
  5. <u-avatar src="/static/logo.png" size="200"></u-avatar>
  6. <view class="nickname">登录</view>
  7. </view>
  8. <!-- 输入框 -->
  9. <view class="body">
  10. <u-form :model="form1" ref="uForm" style="width: 100%;">
  11. <u-form-item label-width="0" prop="username" :borderBottom="false">
  12. <u-input border placeholder="请输入用户名" v-model="form1.username" type="text" height="90"></u-input>
  13. </u-form-item>
  14. <u-form-item label-width="0" prop="password" :borderBottom="false">
  15. <u-input border placeholder="请输入密码" v-model="form1.password" type="password" height="90"></u-input>
  16. </u-form-item>
  17. </u-form>
  18. <u-gap></u-gap>
  19. <u-button class="bwin-btn-100 u-m-b-10" type="primary" @click="loginHandle">登录</u-button>
  20. <!-- <u-button class="bwin-btn-100">取消</u-button> -->
  21. </view>
  22. <!-- 忘记密码导航 -->
  23. <view class="function-row">
  24. <!-- <navigator url="/pages/user/login/login">忘记密码</navigator>
  25. <text style="margin: 0 16rpx;">|</text> -->
  26. <navigator url="/pages/user/login/register">立即注册</navigator>
  27. </view>
  28. <!-- 三方登录 -->
  29. <!-- #ifdef MP-WEIXIN -->
  30. <u-line margin="40rpx 0 0 0"></u-line>
  31. <view class="third-login u-m-b-40">
  32. <u-line margin="0 0 40rpx 0"></u-line>
  33. <view class="login-icon-item">
  34. <u-icon name="weixin-fill" size="64" color="#19be6b" label="微信一键登录" labelPos="bottom" labelSize="24"></u-icon>
  35. <!-- @click="loginByWeixinModalShow = true" -->
  36. </view>
  37. </view>
  38. <u-modal
  39. v-model="loginByWeixinModalShow"
  40. title="提示"
  41. content="未注册用户请先完成注册并绑定微信后再使用微信登录~"
  42. showCancelButton
  43. showConfirmButton
  44. confirmText="继续微信登录"
  45. @confirm="loginByWeixin()"
  46. ></u-modal>
  47. <!-- #endif -->
  48. <view class="footer">
  49. 登录即代表同意
  50. <text class="agreement">《用户协议》</text>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. var that;
  56. export default {
  57. data() {
  58. // 页面数据变量
  59. return {
  60. loginByWeixinModalShow: false, // 微信登录提醒
  61. // init请求返回的数据
  62. data: {},
  63. // 表单请求数据
  64. form1: {
  65. username: '',
  66. password: ''
  67. },
  68. rules: {
  69. username: [
  70. {
  71. required: true,
  72. message: '请输入账号',
  73. // 可以单个或者同时写两个触发验证方式
  74. trigger: 'blur,change'
  75. },
  76. ],
  77. password: [
  78. {
  79. min: 6,
  80. message: '密码不能少于6个字符',
  81. trigger: 'change'
  82. },
  83. ]
  84. },
  85. scrollTop: 0
  86. };
  87. },
  88. onPageScroll(e) {
  89. this.scrollTop = e.scrollTop;
  90. },
  91. // 监听 - 页面每次【加载时】执行(如:前进)
  92. onLoad(options = {}) {
  93. that = this;
  94. that.options = options;
  95. // if (xxx.checkToken()) {
  96. // xxx.toast('您已登录', 'none', 1500, true, function() {
  97. // xxx.navigateToHome();
  98. // });
  99. // }
  100. that.init(options);
  101. },
  102. // 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快,会在页面进入动画完成前触发
  103. onReady() {
  104. this.$refs.uForm.setRules(this.rules);
  105. },
  106. /**
  107. * 监听 - 点击右上角转发时 文档 https://uniapp.dcloud.io/api/plugins/share?id=onshareappmessage
  108. * 如果删除onShareAppMessage函数,则微信小程序右上角转发按钮会自动变灰
  109. */
  110. onShareAppMessage(options) {},
  111. // 函数
  112. methods: {
  113. // 页面数据初始化函数
  114. async init(options = {}) {
  115. const username = uni.getStorageSync('MD_phone')
  116. this.form1.username = username
  117. },
  118. // 账密登录
  119. loginHandle() {
  120. this.$refs.uForm.validate(valid => {
  121. if (valid) {
  122. uni.api.base.apilogin({
  123. phone: this.form1.username,
  124. password: this.form1.password,
  125. }).then(res => {
  126. console.log(res)
  127. uni.setStorageSync('MD_userInfo', res)
  128. uni.setStorageSync('MD_phone', res.phone)
  129. uni.setStorageSync('MD_token', res.token)
  130. uni.$msg('登录成功~')
  131. uni.navigateTo({
  132. url: '/pages/index/index'
  133. })
  134. })
  135. } else {
  136. console.log('验证失败');
  137. return;
  138. }
  139. });
  140. // 发送登录请求
  141. // vk.userCenter.login({
  142. // data: {
  143. // username: that.form1.username,
  144. // password: that.form1.password
  145. // },
  146. // success: res => {
  147. // // 成功后的逻辑
  148. // vk.callFunction({
  149. // url: 'client/agent/kh/getAgentInfo',
  150. // needAlert: false
  151. // }).then(res => {
  152. // vk.vuex.set('$user.agentInfo', res.info);
  153. // vk.alert('登录成功', '确定', '提示', function() {
  154. // vk.navigateToHome();
  155. // });
  156. // });
  157. // }
  158. // });
  159. },
  160. // 微信登录
  161. loginByWeixin() {
  162. // vk.userCenter.loginByWeixin({
  163. // data: {
  164. // type: 'login' // 无账号不注册
  165. // },
  166. // success: data => {
  167. // // 成功后的逻辑
  168. // vk.callFunction({
  169. // url: 'client/agent/kh/getAgentInfo',
  170. // needAlert: false
  171. // }).then(res => {
  172. // vk.vuex.set('$user.agentInfo', res.info);
  173. // vk.alert('登录成功', '确定', '提示', function() {
  174. // vk.navigateToHome();
  175. // });
  176. // });
  177. // }
  178. // });
  179. }
  180. },
  181. // 监听器
  182. watch: {},
  183. // 计算属性
  184. computed: {}
  185. };
  186. </script>
  187. <style lang="scss" scoped>
  188. .header {
  189. padding-top: 15%;
  190. margin-bottom: 40rpx;
  191. display: flex;
  192. flex-direction: column;
  193. align-items: center;
  194. .avatar {
  195. width: 200rpx;
  196. height: 200rpx;
  197. display: flex;
  198. align-items: center;
  199. justify-content: center;
  200. margin-bottom: 20rpx;
  201. }
  202. .nickname {
  203. font-size: $u-h3;
  204. }
  205. }
  206. .body {
  207. width: 100%;
  208. display: flex;
  209. flex-direction: column;
  210. align-items: center;
  211. padding: 20rpx 100rpx;
  212. margin: 40rpx 0;
  213. .title {
  214. font-size: $u-p;
  215. margin-bottom: 20rpx;
  216. }
  217. .tips {
  218. font-size: $u-p2;
  219. color: $u-tips-color;
  220. margin-bottom: 60rpx;
  221. }
  222. }
  223. .third-login {
  224. display: flex;
  225. flex-direction: column;
  226. align-items: center;
  227. justify-content: center;
  228. padding: 32rpx;
  229. }
  230. .function-row {
  231. font-size: $u-p2;
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. margin: 0 auto;
  236. width: 300rpx;
  237. }
  238. .footer {
  239. position: absolute;
  240. width: 100%;
  241. text-align: center;
  242. bottom: 20rpx;
  243. font-size: $u-p2;
  244. color: $u-content-color;
  245. .agreement {
  246. color: $u-theme-color;
  247. }
  248. }
  249. </style>