登录完成,等接口完成
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
"axios-miniprogram-adapter": "^0.3.5",
|
"axios-miniprogram-adapter": "^0.3.5",
|
||||||
"dayjs": "^1.11.7",
|
"dayjs": "^1.11.7",
|
||||||
"pinia": "^2.0.28",
|
"pinia": "^2.0.28",
|
||||||
|
"pinia-plugin-persist-uni": "^1.2.0",
|
||||||
"query-string": "^8.1.0",
|
"query-string": "^8.1.0",
|
||||||
"vue": "^3.2.45",
|
"vue": "^3.2.45",
|
||||||
"vue-i18n": "^9.1.9"
|
"vue-i18n": "^9.1.9"
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import {createSSRApp} from "vue";
|
import {createSSRApp} from "vue";
|
||||||
import App from "./App.vue";
|
import App from "./App.vue";
|
||||||
import util from "./utils/util";
|
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() {
|
export function createApp() {
|
||||||
const app = createSSRApp(App);
|
const app = createSSRApp(App);
|
||||||
Object.keys(util).map(e => app.config.globalProperties[e] = util[e])
|
Object.keys(util).map(e => app.config.globalProperties[e] = util[e])
|
||||||
app.use(createPinia())
|
const store = Pinia.createPinia()
|
||||||
return {
|
store.use(persist)
|
||||||
app,
|
app.use(store)
|
||||||
};
|
return {app, Pinia};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
import {mainStore} from "../../utils/pinia";
|
import {mainStore} from "../../utils/pinia";
|
||||||
import AiItem from "../../components/AiItem";
|
import AiItem from "../../components/AiItem";
|
||||||
import AiBottom from "../../components/AiBottom";
|
import AiBottom from "../../components/AiBottom";
|
||||||
|
import {mapActions} from "pinia/dist/pinia";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "AppAuth",
|
name: "AppAuth",
|
||||||
@@ -30,16 +31,13 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapActions(mainStore, ['getToken', 'getCode']),
|
||||||
handleAvatar({detail}) {
|
handleAvatar({detail}) {
|
||||||
this.form.avatar = detail.avatarUrl
|
this.form.avatar = detail.avatarUrl
|
||||||
},
|
},
|
||||||
handleSignIn() {
|
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>
|
</script>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import axios from 'axios'
|
|||||||
import adapter from 'axios-miniprogram-adapter'
|
import adapter from 'axios-miniprogram-adapter'
|
||||||
|
|
||||||
const instance = axios.create({
|
const instance = axios.create({
|
||||||
|
baseURL: "http://localhost:7001",
|
||||||
timeout: 600000,
|
timeout: 600000,
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
adapter
|
adapter
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ export const mainStore = defineStore('main', {
|
|||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
getCode(count = 0) {
|
getCode(count = 0) {
|
||||||
console.log("getCode:%s", count)
|
|
||||||
if (count > 3) {
|
if (count > 3) {
|
||||||
return Promise.reject("无法获取code")
|
return Promise.reject("无法获取code")
|
||||||
} else return new Promise((resolve, reject) => {
|
} else return new Promise((resolve, reject) => {
|
||||||
@@ -25,13 +24,13 @@ export const mainStore = defineStore('main', {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
getToken(params) {
|
getToken(params) {
|
||||||
http.post("/api/auth/token", null, {
|
return http.post("/api/wxmp/token", null, {
|
||||||
withoutToken: true,
|
withoutToken: true,
|
||||||
headers: {passport: "c799f2d92de34b97"},
|
headers: {passport: "c799f2d92de34b97"},
|
||||||
params: {...params}
|
params: {...params}
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res?.data) {
|
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