登录完成,等接口完成
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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//设置订阅与组件分离,修复持久化失效的问题
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user