login.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="content">
  3. <view class="logo">
  4. <image style="height:104rpx;width:104rpx" src="/static/logo.png" mode="aspectFit" />
  5. <view class="app-name">计数通</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. <!-- 切换登陆方式/注册 -->
  33. <view class="login-opertion">
  34. <!-- <span class="flex" @click="changeLoginType">{{ loginType == 1 ? $t('login.phoneLogin') : $t('login.pwdLogin')
  35. }}</span>
  36. <span class="line"></span> -->
  37. <span class="flex" @click="toRegister">{{ $t('login.register') }}</span>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. userLogin,
  44. getTenantByUsername,
  45. getUserInfo
  46. } from "../../api/login"
  47. import {
  48. encryption,
  49. getTenantCacheList
  50. } from '../../utils/util'
  51. import {
  52. mapMutations
  53. } from 'vuex';
  54. export default {
  55. data() {
  56. return {
  57. time: 0,
  58. timer: undefined,
  59. isGetCode: false,
  60. loginType: 1,
  61. agree: [1],
  62. option: [{
  63. text: '',
  64. value: 1,
  65. }],
  66. currentLanguage: '',
  67. canLogin: false,
  68. needCode:false,
  69. loginForm: {
  70. username: "",
  71. password: "",
  72. code: "",
  73. randomStr: "blockPuzzle",
  74. },
  75. phoneLoginForm: {
  76. mobile: "",
  77. code: "",
  78. },
  79. }
  80. },
  81. onLoad(options) {
  82. if (uni.getStorageSync('CURRENT_LANG') == "en") {
  83. this.currentLanguage = 'English';
  84. } else if (uni.getStorageSync('CURRENT_LANG') == "pt") {
  85. this.currentLanguage = 'Português';
  86. } else if (uni.getStorageSync('CURRENT_LANG') == "uz") {
  87. this.currentLanguage = "O'zbekcha";
  88. } else if (uni.getStorageSync('CURRENT_LANG') == "ru") {
  89. this.currentLanguage = "Russian";
  90. }else {
  91. this.currentLanguage = '简体中文';
  92. }
  93. if (options.username) {
  94. this.loginForm.username = options.username
  95. this.phoneLoginForm.mobile = options.username
  96. this.getTenantUsername()
  97. }
  98. },
  99. methods: {
  100. ...mapMutations({
  101. setUserInfo: 'user/login'
  102. }),
  103. //去注册
  104. toRegister() {
  105. uni.navigateTo({
  106. url: '/pages/login/register'
  107. })
  108. },
  109. //账号登录
  110. onAccountLogin() {
  111. console.log("登录信息、", this.loginForm);
  112. if (this.noRegisterUserName == this.loginForm.username) {
  113. uni.showModal({
  114. content: this.$t('login.noRegister'),
  115. showCancel: false,
  116. })
  117. return
  118. }
  119. if (this.loginForm.username == '') {
  120. uni.showToast({
  121. title: this.$t('login.placeholder'),
  122. icon: "none",
  123. duration: 2500,
  124. })
  125. } else if (this.loginForm.password == '') {
  126. uni.showToast({
  127. title: this.$t('login.passwordPlaceholder'),
  128. icon: "none",
  129. duration: 2500,
  130. })
  131. } else {
  132. const userInfo = encryption({
  133. data: {
  134. username: this.loginForm.username,
  135. password: this.loginForm.password,
  136. delFlag: '0',
  137. source: 'mini'
  138. },
  139. key: 'pigxpigxpigxpigx',
  140. param: ['password'],
  141. source: 'mini'
  142. })
  143. userLogin(userInfo).then(res => {
  144. if (res.statusCode === 200) {
  145. var userId = res.data.user_id
  146. if (!userId) {
  147. userId = res.data.user_info.id
  148. }
  149. uni.setStorageSync('userId', userId)
  150. uni.setStorageSync('userName', this.loginForm.username)
  151. uni.setStorageSync('token', res.data.access_token)
  152. this.onGetUserInfo(true)
  153. }
  154. })
  155. }
  156. },
  157. //获取用户详情
  158. onGetUserInfo() {
  159. getUserInfo().then(res => {
  160. if (res.statusCode == 200 && res.data.code == 0) {
  161. console.log(res);
  162. var userType = res.data.data.sysUser.type;
  163. uni.setStorageSync('userInfo', res.data.data.sysUser)
  164. uni.setStorageSync('tenantInfo', res.data.data.tenantList)
  165. getApp().globalData.tabIndex = 'home'
  166. uni.switchTab({
  167. url: "/pages/home/home"
  168. })
  169. uni.showToast({
  170. title: this.$t('login.success'),
  171. icon: "none",
  172. duration: 2500,
  173. })
  174. this.setUserInfo(res.data.data.sysUser)
  175. } else if (res.statusCode != 200 || res.data.code === 1) {
  176. uni.showToast({
  177. title: res.data.error || res.data.msg,
  178. icon: 'none',
  179. duration: 2000
  180. })
  181. }
  182. })
  183. },
  184. //获取租户
  185. getTenantUsername() {
  186. if (
  187. !this.loginForm.username.length ||
  188. this.loginForm.username.length == 0
  189. ) {
  190. return false;
  191. }
  192. getTenantByUsername(this.loginForm.username).then(response => {
  193. let tenantList = response.data.data ? response.data.data : [];
  194. if(tenantList.length!=0){
  195. uni.setStorageSync('tenantId', tenantList[0].id);
  196. uni.setStorageSync('tenantName', tenantList[0].name);
  197. }else{
  198. uni.showToast({
  199. title: "获取租户失败",
  200. icon: 'none',
  201. duration: 2000
  202. });
  203. }
  204. });
  205. },
  206. }
  207. }
  208. </script>
  209. <style>
  210. /* #ifndef APP-NVUE */
  211. view {
  212. display: flex;
  213. box-sizing: border-box;
  214. flex-direction: column;
  215. }
  216. page {
  217. box-sizing: border-box;
  218. padding: 0 48rpx 80rpx;
  219. height: 100%;
  220. }
  221. /* #endif*/
  222. </style>
  223. <style lang="scss" scoped>
  224. @import '../../common/css/login.scss';
  225. </style>