增加开发环境 mock
This commit is contained in:
@@ -43,10 +43,10 @@
|
||||
import $moment from "moment";
|
||||
import { reactive, ref } from "vue";
|
||||
import router from '../../router'
|
||||
import { useTenantStore } from '../../store/tenant'
|
||||
import { tenantStore } from '../../store/tenant'
|
||||
import { logout } from '../../api/user'
|
||||
// obtain user infomation
|
||||
const tenant = useTenantStore()
|
||||
const tenant = tenantStore()
|
||||
tenant.reflush()
|
||||
const dialogVisible = ref(false)
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref } from 'vue'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import { useTenantStore } from '../../store/tenant'
|
||||
import { tenantStore } from '../../store/tenant'
|
||||
import router from '../../router'
|
||||
import baiduCloudImage from "../../assets/baiducloud.png"
|
||||
import config from '../../const/config'
|
||||
@@ -42,7 +42,7 @@ import config from '../../const/config'
|
||||
|
||||
let qrcode = config.BAIDU_CLOUD_URL + config.RESPONSE_TYPE + config.CLIENT_ID + config.REDIRECT_URI + config.SCOPE + config.DEVICE_ID + config.QR_CODE + config.DISPLAY
|
||||
|
||||
const tenant = useTenantStore()
|
||||
const tenant = tenantStore()
|
||||
|
||||
const ruleFormRef = ref<FormInstance>()
|
||||
const loginForm = reactive({
|
||||
|
||||
+9
-5
@@ -3,7 +3,6 @@ import App from './App.vue'
|
||||
import ElementPlus from "element-plus";
|
||||
import 'element-plus/dist/index.css'
|
||||
import router from './router'
|
||||
// vue store
|
||||
import { createPinia } from 'pinia'
|
||||
const store = createPinia()
|
||||
|
||||
@@ -16,6 +15,11 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
app.component(key, component)
|
||||
}
|
||||
|
||||
import { setupMock } from '../mock'
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
setupMock()
|
||||
}
|
||||
|
||||
app.use(router)
|
||||
app.use(ElementPlus)
|
||||
@@ -23,6 +27,7 @@ app.use(store)
|
||||
import { getToken, getTenant, setToken, setTenant } from './utils/auth'
|
||||
import { Tenant } from './entity/index'
|
||||
import Cookies from 'js-cookie'
|
||||
import { tenantStore } from './store/tenant'
|
||||
const whiteList = ['/login', '/register', '/sorryPage']
|
||||
let url = window.location.href
|
||||
|
||||
@@ -51,12 +56,11 @@ async function checktoken(url: string) {
|
||||
query_data[parameter_list[0]] = parameter_list[1]
|
||||
})
|
||||
const tenant = {
|
||||
id: query_data.tenantId,
|
||||
tenant_id: query_data.tenantId,
|
||||
account: query_data.account
|
||||
}
|
||||
|
||||
setToken(query_data.token as string)
|
||||
setTenant(tenant)
|
||||
const tenant_store = tenantStore()
|
||||
await tenant_store.login(tenant, query_data.token)
|
||||
|
||||
const { href } = router.resolve({
|
||||
path: '/'
|
||||
|
||||
+8
-5
@@ -14,7 +14,7 @@ import { Tenant } from '../entity/index'
|
||||
// return Promise.reject(new Error('invalid credentials'))
|
||||
// }
|
||||
|
||||
export const useTenantStore = defineStore({
|
||||
export const tenantStore = defineStore({
|
||||
id: 'tenant',
|
||||
state: () => ({
|
||||
account: '',
|
||||
@@ -41,11 +41,13 @@ export const useTenantStore = defineStore({
|
||||
* @param {string} user_id
|
||||
* @param {string} user_password
|
||||
*/
|
||||
async login(user_id: string, user_password: string) {
|
||||
const userData = await authorize({ user_id, user_password })
|
||||
async login(tenant: any, token: string) {
|
||||
const userData = await authorize({
|
||||
tenant_id: tenant.tenant_id, token: token
|
||||
})
|
||||
if (userData.data.token) {
|
||||
this.$patch({
|
||||
account: user_id,
|
||||
account: tenant.tenant_id,
|
||||
|
||||
...userData.data,
|
||||
id: 'true'
|
||||
@@ -54,6 +56,7 @@ export const useTenantStore = defineStore({
|
||||
setTenant(userData)
|
||||
console.log('authorize success!')
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (userData.data.message) {
|
||||
reject(userData.data.message)
|
||||
@@ -77,5 +80,5 @@ export const useTenantStore = defineStore({
|
||||
})
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.accept(acceptHMRUpdate(useTenantStore, import.meta.hot))
|
||||
import.meta.hot.accept(acceptHMRUpdate(tenantStore, import.meta.hot))
|
||||
}
|
||||
@@ -84,9 +84,9 @@ import { CopyDocument } from "@element-plus/icons-vue";
|
||||
import { ElNotification } from 'element-plus'
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { h } from 'vue'
|
||||
import { useTenantStore } from '../../store/tenant'
|
||||
import { tenantStore } from '../../store/tenant'
|
||||
// obtain user infomation
|
||||
const Tenant = useTenantStore()
|
||||
const Tenant = tenantStore()
|
||||
|
||||
// 定义书签格式
|
||||
type Bookmark = {
|
||||
|
||||
Reference in New Issue
Block a user