登录完成,等接口完成

This commit is contained in:
aixianling
2023-01-13 11:42:08 +08:00
parent 6fc33e31e0
commit 9c26e09326
5 changed files with 18 additions and 14 deletions

View File

@@ -26,6 +26,7 @@
"axios-miniprogram-adapter": "^0.3.5",
"dayjs": "^1.11.7",
"pinia": "^2.0.28",
"pinia-plugin-persist-uni": "^1.2.0",
"query-string": "^8.1.0",
"vue": "^3.2.45",
"vue-i18n": "^9.1.9"

View File

@@ -1,13 +1,14 @@
import {createSSRApp} from "vue";
import App from "./App.vue";
import util from "./utils/util";
import {createPinia} from "pinia/dist/pinia";
import * as Pinia from "pinia/dist/pinia";
import persist from "pinia-plugin-persist-uni";
export function createApp() {
const app = createSSRApp(App);
Object.keys(util).map(e => app.config.globalProperties[e] = util[e])
app.use(createPinia())
return {
app,
};
const store = Pinia.createPinia()
store.use(persist)
app.use(store)
return {app, Pinia};
}

View File

@@ -16,6 +16,7 @@
import {mainStore} from "../../utils/pinia";
import AiItem from "../../components/AiItem";
import AiBottom from "../../components/AiBottom";
import {mapActions} from "pinia/dist/pinia";
export default {
name: "AppAuth",
@@ -30,16 +31,13 @@ export default {
}
},
methods: {
...mapActions(mainStore, ['getToken', 'getCode']),
handleAvatar({detail}) {
this.form.avatar = detail.avatarUrl
},
handleSignIn() {
this.store.getCode().then(code => this.store.getToken({...this.form, code})).then(() => uni.navigateBack())
this.getCode().then(code => this.getToken({...this.form, code})).then(() => uni.navigateBack())
}
},
setup() {
const store = mainStore()
return {store}
}
}
</script>

View File

@@ -2,6 +2,7 @@ import axios from 'axios'
import adapter from 'axios-miniprogram-adapter'
const instance = axios.create({
baseURL: "http://localhost:7001",
timeout: 600000,
withCredentials: true,
adapter

View File

@@ -8,7 +8,6 @@ export const mainStore = defineStore('main', {
}),
actions: {
getCode(count = 0) {
console.log("getCode:%s", count)
if (count > 3) {
return Promise.reject("无法获取code")
} else return new Promise((resolve, reject) => {
@@ -25,13 +24,13 @@ export const mainStore = defineStore('main', {
})
},
getToken(params) {
http.post("/api/auth/token", null, {
return http.post("/api/wxmp/token", null, {
withoutToken: true,
headers: {passport: "c799f2d92de34b97"},
params: {...params}
}).then(res => {
if (res?.data) {
this.token = res.data
return this.token = res.data
}
})
},
@@ -42,5 +41,9 @@ export const mainStore = defineStore('main', {
}
})
}
}
},
persist: {
enabled: true,
detached: true//设置订阅与组件分离,修复持久化失效的问题
},
})