login.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="login-wrap">
  3. <!-- <view v-if="!buildType" style="text-align: center;color: #999999;padding-top: 40px;">{{ envTips }}</view> -->
  4. <image src="../../static/logos.png" class="logo"></image>
  5. <form class="login-form" @submit="formSubmit">
  6. <view class="form-item">
  7. <u-icon size="34" color="#999" name="account"></u-icon>
  8. <input v-model="form.username" class="item-inp" name="username" type="text" maxlength="30" placeholder="请输入用户名" />
  9. </view>
  10. <view class="form-item">
  11. <u-icon size="34" color="#999" name="lock"></u-icon>
  12. <input v-model="form.password" class="item-inp" name="password" password type="text" maxlength="12" placeholder="请输入密码" />
  13. </view>
  14. <view class="flex-box" style="margin-top: 60rpx;">
  15. <view class="remember-pass">
  16. <u-checkbox v-model="isRemember" value="true" :size="30" :label-size="26" active-color="#e84131" class="login-form-checkbox" @change="rememberChange">记住密码</u-checkbox>
  17. </view>
  18. </view>
  19. <view class="form-btn-con">
  20. <button class="form-btn" form-type="submit">登录</button>
  21. </view>
  22. </form>
  23. <view class="authUserYs">
  24. <u-checkbox v-model="isAuthuserYs" value="true" :size="30" :label-size="26" active-color="#e84131" class="login-form-checkbox" @change="authuserChange">登录代表同意</u-checkbox>
  25. <text @click="toYsPage()" style="vertical-align: text-top;font-size: 26rpx;text-decoration: underline;">章鱼合作商端用户协议及隐私保护政策</text>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. // import market from "@/js_sdk/dc-market/market.js"
  31. // import { checkVersionToLoadUpdate, setStorageForAppVersion,clzConfirm } from '@/libs/tools'
  32. // import { isvalidPhone } from '@/libs/validate.js';
  33. import { login } from '@/api/user.js';
  34. import { getSysVersion } from '@/api/data.js'
  35. export default {
  36. data() {
  37. return {
  38. form: {
  39. username: this.$store.state.vuex_user.account,
  40. password: this.$store.state.vuex_user.password
  41. },
  42. isRemember: true, // 是否记住密码
  43. isAuthuserYs: false, // 是否同意隐私政策
  44. envTips: '',
  45. buildType: '',
  46. };
  47. },
  48. mounted() {
  49. this.isRemember = this.$store.state.vuex_isRemember || true;
  50. this.isAuthuserYs = this.$store.state.vuex_isUsrAuthYs || false;
  51. this.envTips = getApp().globalData.envTips;
  52. this.buildType = getApp().globalData.buildType;
  53. },
  54. onShow() {
  55. },
  56. methods: {
  57. // 获取微信login code
  58. getWechatCode(){
  59. const _this = this
  60. wx.login({
  61. success (res) {
  62. if (res.code) {
  63. //发起网络请求
  64. let formData = JSON.parse(JSON.stringify(_this.form))
  65. formData.code = res.code
  66. _this.submitForm(formData)
  67. } else {
  68. console.log('登录失败,点击“登录”重试!' + res.errMsg)
  69. }
  70. }
  71. })
  72. },
  73. // 表单提交
  74. formSubmit() {
  75. const _this = this;
  76. // 表单校验
  77. if (_this.form.username == '') {
  78. uni.showToast({ icon: 'none', title: '请输入用户名' });
  79. return;
  80. }
  81. // if (!isvalidPhone(_this.form.username)) {
  82. // uni.showToast({ icon: 'none', title: '请输入正确的手机号码' });
  83. // return;
  84. // }
  85. if (_this.form.password == '') {
  86. uni.showToast({ icon: 'none', title: '请输入密码' });
  87. return;
  88. }
  89. if (_this.form.password.length < 6 || _this.form.password.length > 12) {
  90. uni.showToast({ icon: 'none', title: '请输入6-12位密码' });
  91. return;
  92. }
  93. if (!_this.isAuthuserYs) {
  94. uni.showToast({ icon: 'none', title: '请同意并阅读用户隐私政策' });
  95. return;
  96. }
  97. uni.showLoading({
  98. title: '正在登录...'
  99. });
  100. this.submitForm(_this.form)
  101. },
  102. submitForm(formData){
  103. const _this = this;
  104. // 登录
  105. login(formData).then(res => {
  106. uni.hideLoading();
  107. if (res.status == 200) {
  108. _this.$u.vuex('vuex_token', res.data.access_token);
  109. getApp().globalData.token = res.data.access_token;
  110. _this.$u.vuex('vuex_userData', res.data.auth_user);
  111. //登录成功将用户名密码存储到用户本地
  112. if (_this.isRemember) {
  113. //用户勾选“记住密码”
  114. _this.$u.vuex('vuex_user.account', _this.form.username);
  115. _this.$u.vuex('vuex_user.password', _this.form.password);
  116. } else {
  117. //用户没有勾选“记住密码”
  118. _this.$u.vuex('vuex_user.account', '');
  119. _this.$u.vuex('vuex_user.password', '');
  120. _this.form.username = '';
  121. _this.form.password = '';
  122. }
  123. uni.setStorageSync('loginTimeOut', 'NO');
  124. if(res.data.auth_user.mustChangePwd == 0){
  125. _this.toMain();
  126. }else{
  127. uni.reLaunch({
  128. url: '/pages/userCenter/changePwd'
  129. })
  130. }
  131. } else {
  132. uni.showToast({ icon: 'none', title: res.message });
  133. }
  134. });
  135. },
  136. toMain() {
  137. // 跳转到首页
  138. uni.switchTab({
  139. // url: '/pages/index/index',
  140. url: '/pages/workOrder/sellOrder/chooseBundle'
  141. });
  142. },
  143. // 忘记密码
  144. forgetPass() {
  145. uni.navigateTo({
  146. url: '/pages/login/forget-pass?username=' + this.form.username
  147. });
  148. },
  149. // 判断是否记住密码
  150. rememberChange(e) {
  151. this.isRemember = e.value;
  152. },
  153. // 隐私
  154. authuserChange(e) {
  155. this.isAuthuserYs = e.value;
  156. this.$u.vuex('vuex_isUsrAuthYs', this.isAuthuserYs);
  157. },
  158. toYsPage() {
  159. uni.navigateTo({
  160. url: '/pages/agreement/agreement'
  161. });
  162. }
  163. }
  164. };
  165. </script>
  166. <style scoped lang="scss">
  167. @import './login.scss';
  168. </style>