mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-12 04:16:47 +08:00
--fix 路径图整体修改
This commit is contained in:
@@ -20,9 +20,21 @@ export function useBoeApiPage(_url, params = {}, config = {
|
||||
total: 0
|
||||
})
|
||||
|
||||
if (isRef(params)) {
|
||||
watch(params.value, () => {
|
||||
fetch()
|
||||
})
|
||||
}
|
||||
|
||||
if (isRef(_url)) {
|
||||
watchEffect(fetch)
|
||||
} else {
|
||||
fetch()
|
||||
}
|
||||
|
||||
function fetch() {
|
||||
state.loading = true
|
||||
return boeRequest(_url, params).then(r => {
|
||||
return boeRequest(unref(_url), unref(params)).then(r => {
|
||||
state.data = config.result(r)
|
||||
state.totalPage = config.totalPage(r)
|
||||
state.total = config.total(r)
|
||||
@@ -31,7 +43,7 @@ export function useBoeApiPage(_url, params = {}, config = {
|
||||
})
|
||||
}
|
||||
|
||||
function reset(){
|
||||
function reset() {
|
||||
state.data = []
|
||||
state.loading = false
|
||||
state.page = 1
|
||||
@@ -110,13 +122,13 @@ export function useBoeUserListPage(_url, params = {}, init = true) {
|
||||
};
|
||||
}
|
||||
|
||||
export function usePage(_url, params, init = true) {
|
||||
export function useRowsPage(_url, params, init = true) {
|
||||
|
||||
const state = reactive({
|
||||
data: [],
|
||||
total:1,
|
||||
current:1,
|
||||
pages:1,
|
||||
total: 1,
|
||||
current: 1,
|
||||
pages: 1,
|
||||
loading: false
|
||||
})
|
||||
|
||||
@@ -132,7 +144,52 @@ export function usePage(_url, params, init = true) {
|
||||
init && fetch()
|
||||
}
|
||||
|
||||
function reset(){
|
||||
function reset() {
|
||||
state.data = []
|
||||
state.loading = false
|
||||
}
|
||||
|
||||
function fetch() {
|
||||
state.loading = true
|
||||
return request(unref(_url), unref(params)).then(r => {
|
||||
state.data = r.data.rows
|
||||
state.current = r.data.current
|
||||
state.pages = r.data.pages
|
||||
state.total = r.data.total
|
||||
state.loading = false
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
fetch,
|
||||
reset,
|
||||
};
|
||||
}
|
||||
|
||||
export function usePage(_url, params, init = true) {
|
||||
|
||||
const state = reactive({
|
||||
data: [],
|
||||
total: 1,
|
||||
current: 1,
|
||||
pages: 1,
|
||||
loading: false
|
||||
})
|
||||
|
||||
if (isRef(params)) {
|
||||
watch(params.value, () => {
|
||||
fetch()
|
||||
})
|
||||
}
|
||||
|
||||
if (isRef(_url)) {
|
||||
watchEffect(fetch)
|
||||
} else {
|
||||
init && fetch()
|
||||
}
|
||||
|
||||
function reset() {
|
||||
state.data = []
|
||||
state.loading = false
|
||||
}
|
||||
@@ -185,26 +242,18 @@ export async function boeRequest(_url, params) {
|
||||
let url = s[0]
|
||||
const method = s[1]?.toLowerCase() || 'get'
|
||||
if (method === 'get') {
|
||||
let paramsArray = [];
|
||||
//拼接参数
|
||||
if (params) {
|
||||
Object.keys(params).forEach(key => paramsArray.push(key + '=' + params[key]))
|
||||
if (url.search(/\?/) === -1) {
|
||||
url += '?' + paramsArray.join('&')
|
||||
} else {
|
||||
url += '&' + paramsArray.join('&')
|
||||
}
|
||||
}
|
||||
url.includes('?') ? (url.endsWith('&') || (url += '&')) : (url += '?')
|
||||
url += Object.keys(params).map(key => key + '=' + params[key]).join('&')
|
||||
}
|
||||
const body = method !== 'get' ? params || {} : {}
|
||||
const body = method !== 'get' ? s[2] === 'formData' ? formatFormData(params) : params : {}
|
||||
url = process.env.NODE_ENV === 'development' ? url : window.location.protocol + process.env.VUE_APP_BOE_API_URL + url
|
||||
return fetch(url, {
|
||||
method,
|
||||
headers: {
|
||||
token: getCookieForName('token'),
|
||||
...method !== 'get' ? {'Content-Type': 'application/json'} : {}
|
||||
...method !== 'get' && s[2] !== 'formData' ? {'Content-Type': 'application/json'} : {}
|
||||
},
|
||||
...method !== 'get' ? {body: JSON.stringify(body)} : {}
|
||||
...method !== 'get' ? {body: s[2] === 'formData' ? body : JSON.stringify(body)} : {}
|
||||
}).then(res => {
|
||||
return res.text()
|
||||
}).then(res => {
|
||||
@@ -212,6 +261,12 @@ export async function boeRequest(_url, params) {
|
||||
})
|
||||
}
|
||||
|
||||
function formatFormData(data) {
|
||||
const formData = new FormData();
|
||||
Object.keys(data).forEach(k => formData.append(k, data[k]))
|
||||
return formData
|
||||
}
|
||||
|
||||
export async function request(_url, params) {
|
||||
const s = _url.split(' ')
|
||||
let url = s[0]
|
||||
|
||||
Reference in New Issue
Block a user