Browse Source

登录调整

sunlupeng 1 year ago
parent
commit
17200a1e51
6 changed files with 54 additions and 5 deletions
  1. 13 0
      api/system/tenant.js
  2. 15 2
      pages/login.vue
  3. 6 0
      pages/mine/index.vue
  4. 2 1
      store/modules/user.js
  5. 16 0
      utils/auth.js
  6. 2 2
      utils/request.js

+ 13 - 0
api/system/tenant.js

@@ -0,0 +1,13 @@
+import request from '@/utils/request'
+
+// 使用用户名,获得租户编号
+export function getTenantIdByName(username) {
+  return request({
+    url: '/system/auth/getCurrentTenantIdByUsername',
+    method: 'get',
+    params: {
+      username
+    }
+  })
+}
+

+ 15 - 2
pages/login.vue

@@ -8,7 +8,7 @@
 		<view class="login-form-content">
 			<view class="input-item flex align-center">
 				<view class="iconfont icon-user icon"></view>
-				<input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
+				<input v-model="loginForm.username" @blur="getTenantIdByName" class="input" type="text" placeholder="请输入账号" maxlength="30" />
 			</view>
 			<view class="input-item flex align-center">
 				<view class="iconfont icon-password icon"></view>
@@ -31,7 +31,8 @@
 
 <script>
 	import Verify from "@/components/verifition/Verify"
-
+	import {getTenantIdByName} from "@/api/system/tenant";
+	import {setTenantId,removeTenantId} from "@/utils/auth";
 	export default {
 		name: 'Login',
 		components: {
@@ -49,6 +50,18 @@
 			}
 		},
 		methods: {
+			getTenantIdByName(e){
+				removeTenantId()
+				let value = e.target.value
+                getTenantIdByName(value).then(res => {
+                  const tenantId = res.data;
+                  if (tenantId && tenantId >= 0) {
+                    setTenantId(tenantId)
+                  } else {
+					this.$modal.msgError("该手机号未创建账号,请重新输入")
+                  }
+                });
+			},
 			// 隐私协议
 			handlePrivacy() {
 				let site = this.globalConfig.appInfo.agreements[0]

+ 6 - 0
pages/mine/index.vue

@@ -38,6 +38,12 @@
             <view>联系我们</view>
           </view>
         </view>
+        <view class="list-cell list-cell-arrow" @click="handleLogout">
+          <view class="menu-item-box">
+            <view class="iconfont icon-user menu-icon"></view>
+            <view>退出登录</view>
+          </view>
+        </view>
       </view>
 
     </view>

+ 2 - 1
store/modules/user.js

@@ -2,7 +2,7 @@ import config from '@/config'
 import storage from '@/utils/storage'
 import constant from '@/utils/constant'
 import { login, logout, getInfo } from '@/api/login'
-import { setToken, removeToken } from '@/utils/auth'
+import { setToken, removeToken,removeTenantId } from '@/utils/auth'
 
 const baseUrl = config.baseUrl
 
@@ -90,6 +90,7 @@ const user = {
           commit('SET_ROLES', [])
           commit('SET_PERMISSIONS', [])
           removeToken()
+          // removeTenantId()
           storage.clean()
           resolve()
         }).catch(error => {

+ 16 - 0
utils/auth.js

@@ -20,3 +20,19 @@ export function removeToken() {
   uni.removeStorageSync(AccessTokenKey)
   uni.removeStorageSync(RefreshTokenKey)
 }
+
+// ========== 租户相关 ==========
+
+const TenantIdKey = 'TENANT_ID'
+
+export function getTenantId() {
+  return localStorage.getItem(TenantIdKey)
+}
+
+export function setTenantId(username) {
+  localStorage.setItem(TenantIdKey, username)
+}
+
+export function removeTenantId() {
+  localStorage.removeItem(TenantIdKey)
+}

+ 2 - 2
utils/request.js

@@ -1,6 +1,6 @@
 import store from '@/store'
 import config from '@/config'
-import { getAccessToken } from '@/utils/auth'
+import { getAccessToken,getTenantId} from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
 import { toast, showConfirm, tansParams } from '@/utils/common'
 
@@ -15,7 +15,7 @@ const request = config => {
     config.header['Authorization'] = 'Bearer ' + getAccessToken()
   }
   // 设置租户 TODO 芋艿:强制 1 先
-  config.header['tenant-id'] = '293';
+  config.header['tenant-id'] = getTenantId();
   // get请求映射params参数
   if (config.params) {
     let url = config.url + '?' + tansParams(config.params)