Skip to content

Commit

Permalink
fix: baseurl
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulter committed Apr 29, 2024
1 parent 9a016b7 commit 16e15ec
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
4 changes: 1 addition & 3 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ import { createApp } from 'vue'
import axios from 'axios'
import store from './store/index.js'
import { ref } from 'vue'
import { useStore } from "vuex"

const app = createApp(App)
app.use(store)

const axiosInstance = axios.create({
withCredentials: true,
baseURL: 'https://dev.campux.idoknow.top'
baseURL: store.state.base_url,
})
app.config.globalProperties.$baseurl = ref('https://dev.campux.idoknow.top')
app.config.globalProperties.$axios = { ...axiosInstance }

registerPlugins(app)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export default {
// 将images中的baseurl去掉
this.post.images = this.post.images.map(image => {
return image.replace(this.$baseurl.value + "/v1/post/download-image/", '')
return image.replace(this.$store.state.base_url + "/v1/post/download-image/", '')
})
this.$axios.post('/v1/post/post-new', this.post)
Expand Down Expand Up @@ -321,7 +321,7 @@ export default {
})
.then(res => {
if (res.data.code === 0) {
let url = this.$baseurl.value + '/v1/post/download-image/' + res.data.data.key
let url = this.$store.state.base_url + '/v1/post/download-image/' + res.data.data.key
console.log(url)
this.post.images.push(url)
this.loading = false
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/pages/world.vue
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export default {
p[i].created_at = date.getUTCFullYear() + "-" + (date.getUTCMonth() + 1) + "-" + date.getUTCDate() + " " + date.getUTCHours() + ":" + date.getUTCMinutes() + ":" + date.getUTCSeconds()
p[i].status = this.statusMap[p[i].status]
for (let j = 0; j < p[i].images.length; j++) {
p[i].images[j] = this.$baseurl.value + "/v1/post/download-image/" + p[i].images[j]
p[i].images[j] = this.$store.state.base_url + "/v1/post/download-image/" + p[i].images[j]
}
}
console.log(p)
Expand Down Expand Up @@ -324,7 +324,7 @@ export default {
p[i].created_at = date.getUTCFullYear() + "-" + (date.getUTCMonth() + 1) + "-" + date.getUTCDate() + " " + date.getUTCHours() + ":" + date.getUTCMinutes() + ":" + date.getUTCSeconds()
p[i].status = this.statusMap[p[i].status]
for (let j = 0; j < p[i].images.length; j++) {
p[i].images[j] = this.$baseurl.value + "/v1/post/download-image/" + p[i].images[j]
p[i].images[j] = this.$store.state.base_url + "/v1/post/download-image/" + p[i].images[j]
}
}
console.log(p)
Expand All @@ -337,11 +337,11 @@ export default {
})
.catch((error) => {
this.pullLoading = false
if (error.response.data.code === -1) {
this.$router.push('/auth?hint=请先登录嗷')
return
}
this.toast('获取稿件失败')
this.toast(error)
// if (error.response.data.code === -1) {
// this.$router.push('/auth?hint=请先登录嗷')
// return
// }
console.log(error)
})
},
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import axios from 'axios'

export default createStore({
state: {
base_url: "https://dev.campux.idoknow.top",
metadata: {
"banner": "",
"popup_announcement": "",
Expand All @@ -15,7 +16,7 @@ export default createStore({
initMetadata(state, key) {
console.log(key)
if (this.state.metadata[key] === "") {
axios.get('https://dev.campux.idoknow.top/v1/misc/get-metadata?key=' + key)
axios.get(this.state.base_url + '/v1/misc/get-metadata?key=' + key)
.then(res => {
if (res.data.code === 0) {
if (key == "post_rules") {
Expand Down

0 comments on commit 16e15ec

Please sign in to comment.