update code

This commit is contained in:
全栈小学生
2023-09-06 14:52:30 +08:00
parent 8f2e36cfa4
commit 36967076d4
1706 changed files with 63614 additions and 17748 deletions

View File

@@ -30,14 +30,18 @@ export function logout() {
* 用户名注册
*/
export function usernameRegister(data: AnyObject) {
return request.post('register', data)
let url = 'register'
data.pid && (url += `?pid=${data.pid}`)
return request.post(url, data)
}
/**
* 手机号注册
*/
export function mobileRegister(data: AnyObject) {
return request.post('register/mobile', data)
let url = 'register/mobile'
data.pid && (url += `?pid=${data.pid}`)
return request.post(url, data)
}
/**
@@ -58,7 +62,9 @@ export function weappLogin(data: AnyObject) {
* 绑定手机号
*/
export function bind(data: AnyObject) {
return request.post('bind', data)
let url = 'bind'
data.pid && (url += `?pid=${data.pid}`)
return request.post(url, data)
}
/**

View File

@@ -2,7 +2,7 @@
* 获取验证码
*/
export function getCaptcha() {
return request.get('captcha', {})
return request.get('captcha', { time: (new Date().getTime()) })
}
/**

View File

@@ -19,7 +19,7 @@ import useMemberStore from '@/stores/member'
import '@/assets/styles/index.scss'
if (process.client) {
const match = location.href.match(/\/s(\d*)\//)
const match = location.href.match(/\/web\/(\d*)\//)
const cookie = useCookie('siteId')
match ? cookie.value = match[1] : cookie.value = null
}

View File

@@ -54,14 +54,9 @@
</template>
<script lang="ts" setup>
import { ref, reactive, computed } from 'vue'
import { bind } from '@/api/auth'
import { bindMobile } from '@/api/member'
import useMemberStore from '@/stores/member'
import { ref, reactive } from 'vue'
import { getArticleCategory,getArticleList } from '@/api/article'
import { FormInstance } from 'element-plus'
import { ArrowRight } from '@element-plus/icons-vue'
import type { TabsPaneContext } from 'element-plus'
import { useRouter } from 'vue-router';
const router = useRouter();
@@ -79,10 +74,6 @@ const articleTableData = reactive({
}
})
const handleClick = (tab: TabsPaneContext, event: Event) => {
console.log(tab, event)
}
/**
* 获取文章列表
*/

View File

@@ -1,28 +1,27 @@
import { breakpointsTailwind } from '@vueuse/core'
import { ElMessage } from 'element-plus'
import useMemberStore from '@/stores/member'
interface ShowMessageConfig {
interface ConfigOption {
showErrorMessage?: boolean
showSuccessMessage?: boolean
showSuccessMessage?: boolean,
headers?: Headers
}
interface FetchOptions {
baseURL: string
method: string
query?: Record<string, any>,
body?: RequestInit['body'] | Record<string, any>
headers: Record<string, any>,
onRequest?: (data: any) => void,
onResponse?: (data: any) => void,
onResponseError?: (data: any) => void,
showMessageConfig?: ShowMessageConfig,
headers: Record<string, any>
onRequest?: (data: any) => void
onResponse?: (data: any) => void
onResponseError?: (data: any) => void
showErrorMessage?: boolean
showSuccessMessage?: boolean
watch: boolean
}
class Http {
private options: FetchOptions = {
baseURL: '',
method: '',
headers: {},
watch: false
}
@@ -38,9 +37,6 @@ class Http {
this.options.headers[runtimeConfig.public.VITE_REQUEST_HEADER_SITEID_KEY] = useCookie('siteId').value || runtimeConfig.public.VITE_SITE_ID
this.options.headers[runtimeConfig.public.VITE_REQUEST_HEADER_CHANNEL_KEY] = 'pc'
if (getToken()) this.options.headers[runtimeConfig.public.VITE_REQUEST_HEADER_TOKEN_KEY] = getToken()
delete this.options.body
delete this.options.query
}
/**
@@ -51,31 +47,32 @@ class Http {
this.handleNetworkError(response)
if (data.code != undefined) {
if (data.code == 1) {
if (options.showMessageConfig.showSuccessMessage) ElMessage({ message: data.msg, type: 'success' })
if (options.showSuccessMessage) ElMessage({ message: data.msg, type: 'success' })
} else {
ElMessage({ message: data.msg, type: 'error' })
if (data.code == 0) {
ElMessage({ message: data.msg, type: 'error' })
} else {
this.handleAuthError(data.code)
}
}
}
}
}
public get(url: string, query = {}, showMessageConfig: ShowMessageConfig = {}) {
this.options.query = query
return this.request(url, 'GET', showMessageConfig)
public get(url: string, query = {}, config: ConfigOption = {}) {
return this.request(url, 'GET', { query }, config)
}
public post(url: string, body = {}, showMessageConfig: ShowMessageConfig = {}) {
this.options.body = body
return this.request(url, 'POST', showMessageConfig)
public post(url: string, body = {}, config: ConfigOption = {}) {
return this.request(url, 'POST', { body }, config)
}
public put(url: string, body = {}, showMessageConfig: ShowMessageConfig = {}) {
this.options.body = body
return this.request(url, 'PUT', showMessageConfig)
public put(url: string, body = {}, config: ConfigOption = {}) {
return this.request(url, 'PUT', { body }, config)
}
public delete(url: string, showMessageConfig: ShowMessageConfig = {}) {
return this.request(url, 'DELETE', showMessageConfig)
public delete(url: string, config: ConfigOption = {}) {
return this.request(url, 'DELETE', {}, config)
}
/**
@@ -85,24 +82,35 @@ class Http {
* @param showMessageConfig
* @returns
*/
private request(url: string, method: string, showMessageConfig: ShowMessageConfig = {}) {
this.options.method = method
this.options.showMessageConfig = showMessageConfig
private request(url: string, method: string, param: AnyObject = {}, config: ConfigOption = {}) {
return new Promise((resolve, reject) => {
setTimeout(() => {
// 处理首次请求baseurl空的问题
const runtimeConfig = useRuntimeConfig()
!this.options.baseURL && (this.options.baseURL = runtimeConfig.public.VITE_APP_BASE_URL || `${location.origin}/api/`)
this.options.baseURL.substr(-1) != '/' && (this.options.baseURL += '/')
useFetch(url, { ...this.options }).then((response) => {
// 处理数组格式
for (const key in param.query) {
if (param.query[key] instanceof Array) {
param.query[key].forEach((item, index) => {
param.query[`${key}[${index}]`] = item
});
delete param.query[key]
}
}
useFetch(url, { ...this.options, method, ...config, ...param }).then((response) => {
const { data: { value }, error } = response
if (value) {
if (value.code == 1) {
if (value.code && value.code == 1) {
resolve(value)
} else {
reject(value)
if (value.type && value.type == 'application/zip') {
resolve(value)
} else {
reject(value)
}
}
} else {
reject(error)
@@ -114,6 +122,14 @@ class Http {
})
}
private handleAuthError(code: number) {
switch (code) {
case 401:
useMemberStore().logout()
break;
}
}
private handleNetworkError(err: any) {
if (err.status && err.status != 200) {
let errMessage = ''