login.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="content">
  3. <view class="logo">
  4. <image style="height:104rpx;width:104rpx" src="/static/czzn-img/login/logo.png" mode="aspectFit" />
  5. <view class="app-name">{{$t('login.e')}}</view>
  6. </view>
  7. <!-- 账号密码登录 -->
  8. <template v-if="loginType == 1">
  9. <view class="inp_box">
  10. <input type="text" v-model="loginForm.username" @blur="getTenantUsername"
  11. :placeholder="this.$t('login.placeholder')" />
  12. </view>
  13. <view class="inp_box">
  14. <input type="password" v-model="loginForm.password"
  15. :placeholder="this.$t('login.passwordPlaceholder')" />
  16. </view>
  17. </template>
  18. <!-- 阅读同意/忘记密码 -->
  19. <view class="agree-forget">
  20. <view class="agree">
  21. <uni-data-checkbox selectedColor="#3275F5" multiple v-model="agree" checked=true :localdata="option">
  22. </uni-data-checkbox>
  23. <span>{{ $t("login.agree") }}</span>
  24. </view>
  25. <!-- <span class="forget" @click="toReset" v-if="loginType == 1">{{ $t('login.forgetPassword') }}</span> -->
  26. </view>
  27. <!-- 登录按钮 -->
  28. <view class="btn-wrap">
  29. <u-button type="primary" shape="circle" :disabled="!agree[0]"
  30. @click="loginType == 1 ? onAccountLogin() : onPhoneLogin()">{{ $t('login.login') }}</u-button>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. userLogin,
  37. getTenantByUsername,
  38. getUserInfo
  39. } from "../../api/login"
  40. import {
  41. encryption,
  42. getTenantCacheList
  43. } from '../../utils/util'
  44. import {
  45. mapMutations
  46. } from 'vuex';
  47. export default {
  48. data() {
  49. return {
  50. time: 0,
  51. timer: undefined,
  52. isGetCode: false,
  53. loginType: 1,
  54. agree: [1],
  55. option: [{
  56. text: '',
  57. value: 1,
  58. }],
  59. currentLanguage: '',
  60. canLogin: false,
  61. needCode:false,
  62. loginForm: {
  63. username: "",
  64. password: "",
  65. code: "",
  66. randomStr: "blockPuzzle",
  67. },
  68. phoneLoginForm: {
  69. mobile: "",
  70. code: "",
  71. },
  72. }
  73. },
  74. onLoad(options) {
  75. if (uni.getStorageSync('CURRENT_LANG') == "en") {
  76. this.currentLanguage = 'English';
  77. } else if (uni.getStorageSync('CURRENT_LANG') == "pt") {
  78. this.currentLanguage = 'Português';
  79. } else if (uni.getStorageSync('CURRENT_LANG') == "uz") {
  80. this.currentLanguage = "O'zbekcha";
  81. } else if (uni.getStorageSync('CURRENT_LANG') == "ru") {
  82. this.currentLanguage = "Russian";
  83. }else {
  84. this.currentLanguage = '简体中文';
  85. }
  86. if (options.username) {
  87. this.loginForm.username = options.username
  88. this.phoneLoginForm.mobile = options.username
  89. this.getTenantUsername()
  90. }
  91. },
  92. methods: {
  93. ...mapMutations({
  94. setUserInfo: 'user/login'
  95. }),
  96. //账号登录
  97. onAccountLogin() {
  98. console.log("登录信息、", this.loginForm);
  99. if (this.noRegisterUserName == this.loginForm.username) {
  100. uni.showModal({
  101. content: this.$t('login.noRegister'),
  102. showCancel: false,
  103. })
  104. return
  105. }
  106. if (this.loginForm.username == '') {
  107. uni.showToast({
  108. title: this.$t('login.placeholder'),
  109. icon: "none",
  110. duration: 2500,
  111. })
  112. } else if (this.loginForm.password == '') {
  113. uni.showToast({
  114. title: this.$t('login.passwordPlaceholder'),
  115. icon: "none",
  116. duration: 2500,
  117. })
  118. } else {
  119. const userInfo = encryption({
  120. data: {
  121. username: this.loginForm.username,
  122. password: this.loginForm.password,
  123. delFlag: '0',
  124. source: 'mini'
  125. },
  126. key: 'pigxpigxpigxpigx',
  127. param: ['password'],
  128. source: 'mini'
  129. })
  130. userLogin(userInfo).then(res => {
  131. if (res.statusCode === 200) {
  132. var userId = res.data.user_id
  133. if (!userId) {
  134. userId = res.data.user_info.id
  135. }
  136. uni.setStorageSync('userId', userId)
  137. uni.setStorageSync('userName', this.loginForm.username)
  138. uni.setStorageSync('token', res.data.access_token)
  139. this.onGetUserInfo(true)
  140. }
  141. })
  142. }
  143. },
  144. //获取用户详情
  145. onGetUserInfo() {
  146. getUserInfo().then(res => {
  147. if (res.statusCode == 200 && res.data.code == 0) {
  148. console.log(res);
  149. var userType = res.data.data.sysUser.type;
  150. uni.setStorageSync('userInfo', res.data.data.sysUser)
  151. uni.setStorageSync('tenantInfo', res.data.data.tenantList)
  152. getApp().globalData.tabIndex = 'home'
  153. uni.switchTab({
  154. url: "/pages/home/home"
  155. })
  156. uni.showToast({
  157. title: this.$t('login.success'),
  158. icon: "none",
  159. duration: 2500,
  160. })
  161. } else if (res.statusCode != 200 || res.data.code === 1) {
  162. uni.showToast({
  163. title: res.data.error || res.data.msg,
  164. icon: 'none',
  165. duration: 2000
  166. })
  167. }
  168. })
  169. },
  170. //获取租户
  171. getTenantUsername() {
  172. if (
  173. !this.loginForm.username.length ||
  174. this.loginForm.username.length == 0
  175. ) {
  176. return false;
  177. }
  178. getTenantByUsername(this.loginForm.username).then(response => {
  179. let tenantList = response.data.data ? response.data.data : [];
  180. if(tenantList.length!=0){
  181. uni.setStorageSync('tenantId', tenantList[0].id);
  182. uni.setStorageSync('tenantName', tenantList[0].name);
  183. }else{
  184. uni.showToast({
  185. title: "获取租户失败",
  186. icon: 'none',
  187. duration: 2000
  188. });
  189. }
  190. });
  191. },
  192. }
  193. }
  194. </script>
  195. <style>
  196. /* #ifndef APP-NVUE */
  197. view {
  198. display: flex;
  199. box-sizing: border-box;
  200. flex-direction: column;
  201. }
  202. page {
  203. box-sizing: border-box;
  204. padding: 0 48rpx 80rpx;
  205. height: 100%;
  206. }
  207. /* #endif*/
  208. </style>
  209. <style lang="scss" scoped>
  210. @import '../../common/css/login.scss';
  211. </style>