调整登录,调整部分接口路径,调整上传图片集合到基本请求中去
This commit is contained in:
parent
decbccedce
commit
79bdca1412
|
|
@ -1,14 +1,18 @@
|
|||
import { client } from '@/utils/client'
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 登录
|
||||
export function login(data: Record<string, any>) {
|
||||
return request.post({ url: '/login/check', data: { ...data, client } })
|
||||
export function mobileLogin(data: Record<string, any>) {
|
||||
return request.post({ url: '/login/mobileLogin', data })
|
||||
}
|
||||
|
||||
// 登录
|
||||
export function accountLogin(data: Record<string, any>) {
|
||||
return request.post({ url: '/login/accountLogin', data })
|
||||
}
|
||||
|
||||
//注册
|
||||
export function register(data: Record<string, any>) {
|
||||
return request.post({ url: '/login/register', data: { ...data, client } })
|
||||
return request.post({ url: '/login/register', data })
|
||||
}
|
||||
|
||||
//忘记密码
|
||||
|
|
@ -21,6 +25,13 @@ export function getWxCodeUrl() {
|
|||
return request.get({ url: '/login/codeUrl', data: { url: location.href } })
|
||||
}
|
||||
|
||||
export function OALogin(data: Record<string, any>) {
|
||||
return request.get({ url: '/login/oaLogin', data })
|
||||
// 微信小程序登录
|
||||
|
||||
export function mnpLogin(data: Record<string, any>) {
|
||||
return request.post({ url: '/login/mnpLogin', data })
|
||||
}
|
||||
|
||||
// 公众号登录
|
||||
export function OALogin(data: Record<string, any>) {
|
||||
return request.post({ url: '/login/oaLogin', data })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,25 @@ import request from '@/utils/request'
|
|||
|
||||
//发送短信
|
||||
export function smsSend(data: any) {
|
||||
return request.post({ url: '/sms/send', data: data })
|
||||
return request.post({ url: '/index/sendSms', data: data })
|
||||
}
|
||||
|
||||
export function getConfig() {
|
||||
return request.get({ url: '/config' })
|
||||
return request.get({ url: '/index/config' })
|
||||
}
|
||||
|
||||
export function getPolicy(data: any) {
|
||||
return request.get({ url: '/policy', data: data })
|
||||
return request.get({ url: '/index/policy', data: data })
|
||||
}
|
||||
|
||||
export function uploadImage(file: any, token?: string) {
|
||||
return request.uploadFile({
|
||||
url: '/upload/image',
|
||||
filePath: file,
|
||||
name: 'file',
|
||||
header: {
|
||||
token
|
||||
},
|
||||
fileType: 'image'
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ import request from '@/utils/request'
|
|||
|
||||
//首页数据
|
||||
export function getIndex() {
|
||||
return request.get({ url: '/index' })
|
||||
return request.get({ url: '/index/index' })
|
||||
}
|
||||
|
||||
// 装修页面
|
||||
export function getDecorate(data: any) {
|
||||
return request.get({ url: '/decorate', data })
|
||||
return request.get({ url: '/index/decorate', data })
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -15,14 +15,5 @@ export function getDecorate(data: any) {
|
|||
* @return { Promise }
|
||||
*/
|
||||
export function getHotSearch() {
|
||||
return request.get({ url: '/hotSearch' })
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 搜索
|
||||
* @param { string } keyword 关键词
|
||||
* @return { Promise }
|
||||
*/
|
||||
export function getSearch(data: { keyword: string; pageNo: number; pageSize: number }) {
|
||||
return request.get({ url: '/search', data })
|
||||
return request.get({ url: '/index/hotSearch' })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,3 +26,8 @@ export enum RequestCodeEnum {
|
|||
REQUEST_404_ERROR = 404, //请求接口不存在
|
||||
SYSTEM_ERROR = 500 //系统错误
|
||||
}
|
||||
|
||||
export enum RequestErrMsgEnum {
|
||||
ABORT = 'request:fail abort',
|
||||
TIMEOUT = 'request:fail timeout'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { login } from '@/api/account'
|
||||
import { mobileLogin, accountLogin, mnpLogin } from '@/api/account'
|
||||
import { smsSend } from '@/api/app'
|
||||
import { SMSEnum } from '@/enums/appEnums'
|
||||
import { BACK_URL } from '@/enums/cacheEnums'
|
||||
|
|
@ -174,8 +174,7 @@ import { onLoad, onShow } from '@dcloudio/uni-app'
|
|||
import { computed, reactive, ref, shallowRef, watch } from 'vue'
|
||||
enum LoginTypeEnum {
|
||||
MOBILE = 'mobile',
|
||||
ACCOUNT = 'account',
|
||||
MNP = 'mnp'
|
||||
ACCOUNT = 'account'
|
||||
}
|
||||
|
||||
enum LoginWayEnum {
|
||||
|
|
@ -242,28 +241,34 @@ const isOpenAgreement = computed(() => appStore.getLoginConfig.openAgreement ==
|
|||
const isOpenOtherAuth = computed(() => appStore.getLoginConfig.openOtherAuth == 1)
|
||||
const isForceBindMobile = computed(() => appStore.getLoginConfig.forceBindMobile == 1)
|
||||
|
||||
const loginFun = async (scene: LoginTypeEnum, code?: string) => {
|
||||
if (!isCheckAgreement.value && isOpenAgreement.value)
|
||||
return uni.$u.toast('请勾选已阅读并同意《服务协议》和《隐私协议》')
|
||||
if (scene == LoginTypeEnum.ACCOUNT) {
|
||||
if (!formData.username) return uni.$u.toast('请输入账号/手机号码')
|
||||
if (!formData.password) return uni.$u.toast('请输入密码')
|
||||
}
|
||||
if (scene == LoginTypeEnum.MOBILE) {
|
||||
if (!formData.mobile) return uni.$u.toast('请输入手机号码')
|
||||
if (!formData.code) return uni.$u.toast('请输入验证码')
|
||||
}
|
||||
const params = {
|
||||
...formData,
|
||||
scene
|
||||
}
|
||||
if (code) params.code = code
|
||||
uni.showLoading({
|
||||
title: '请稍后...'
|
||||
})
|
||||
const loginFun = async (scene: LoginTypeEnum) => {
|
||||
try {
|
||||
const data = await login(params)
|
||||
loginHandle(data)
|
||||
await checkAgreement()
|
||||
if (scene == LoginTypeEnum.ACCOUNT) {
|
||||
if (!formData.username) return uni.$u.toast('请输入账号/手机号码')
|
||||
if (!formData.password) return uni.$u.toast('请输入密码')
|
||||
}
|
||||
if (scene == LoginTypeEnum.MOBILE) {
|
||||
if (!formData.mobile) return uni.$u.toast('请输入手机号码')
|
||||
if (!formData.code) return uni.$u.toast('请输入验证码')
|
||||
}
|
||||
uni.showLoading({
|
||||
title: '请稍后...'
|
||||
})
|
||||
|
||||
let data
|
||||
switch (scene) {
|
||||
case LoginTypeEnum.ACCOUNT:
|
||||
data = await accountLogin(formData)
|
||||
break
|
||||
case LoginTypeEnum.MOBILE:
|
||||
data = await mobileLogin(formData)
|
||||
|
||||
break
|
||||
}
|
||||
if (data) {
|
||||
loginHandle(data)
|
||||
}
|
||||
} catch (error: any) {
|
||||
uni.hideLoading()
|
||||
uni.$u.toast(error)
|
||||
|
|
@ -286,7 +291,7 @@ const loginHandle = async (data: any) => {
|
|||
uni.hideLoading()
|
||||
const pages = getCurrentPages()
|
||||
if (pages.length > 1) {
|
||||
const prevPage = pages.at(-2)
|
||||
const prevPage = pages[pages.length - 2]
|
||||
uni.navigateBack({
|
||||
success: () => {
|
||||
// @ts-ignore
|
||||
|
|
@ -307,19 +312,34 @@ const loginHandle = async (data: any) => {
|
|||
|
||||
const { lockFn: handleLogin } = useLockFn(loginFun)
|
||||
|
||||
const wxLogin = async () => {
|
||||
// #ifdef MP-WEIXIN
|
||||
const data: any = await uni.login({
|
||||
provider: 'weixin'
|
||||
})
|
||||
handleLogin(LoginTypeEnum.MNP, data.code)
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
if (isWeixin.value) {
|
||||
wechatOa.getUrl()
|
||||
}
|
||||
// #endif
|
||||
const checkAgreement = async () => {
|
||||
if (!isCheckAgreement.value && isOpenAgreement.value)
|
||||
return Promise.reject('请勾选已阅读并同意《服务协议》和《隐私协议》')
|
||||
}
|
||||
const { lockFn: wxLogin } = useLockFn(async () => {
|
||||
try {
|
||||
await checkAgreement()
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.showLoading({
|
||||
title: '请稍后...'
|
||||
})
|
||||
const { code }: any = await uni.login({
|
||||
provider: 'weixin'
|
||||
})
|
||||
const data = await mnpLogin({
|
||||
code
|
||||
})
|
||||
loginHandle(data)
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
if (isWeixin.value) {
|
||||
wechatOa.getUrl()
|
||||
}
|
||||
// #endif
|
||||
} catch (error) {
|
||||
uni.$u.toast(error)
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => appStore.getLoginConfig,
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@
|
|||
import { ref, reactive, shallowRef } from 'vue'
|
||||
import Suggest from './component/suggest.vue'
|
||||
import { HISTORY } from '@/enums/cacheEnums'
|
||||
import { getHotSearch, getSearch } from '@/api/shop'
|
||||
import { getHotSearch } from '@/api/shop'
|
||||
import { getArticleList } from '@/api/news'
|
||||
import cache from '@/utils/cache'
|
||||
|
||||
interface Search {
|
||||
|
|
@ -98,7 +99,7 @@ const handleClear = async (): Promise<void> => {
|
|||
|
||||
const queryList = async (pageNo, pageSize) => {
|
||||
try {
|
||||
const { lists } = await getSearch({
|
||||
const { lists } = await getArticleList({
|
||||
keyword: keyword.value,
|
||||
pageNo,
|
||||
pageSize
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ import { onShow, onUnload } from '@dcloudio/uni-app'
|
|||
import { getUserInfo, userEdit, userBindMobile, userMnpMobile } from '@/api/user'
|
||||
import { smsSend } from '@/api/app'
|
||||
import { FieldType, SMSEnum } from '@/enums/appEnums'
|
||||
import { uploadFile } from '@/utils/util'
|
||||
import { uploadImage } from '@/api/app'
|
||||
|
||||
// 用户信息
|
||||
const userInfo = ref<any>({})
|
||||
|
|
@ -342,7 +342,7 @@ const uploadAvatar = (path: string) => {
|
|||
title: '正在上传中...',
|
||||
mask: true
|
||||
})
|
||||
uploadFile(path)
|
||||
uploadImage(path)
|
||||
.then((res) => {
|
||||
uni.hideLoading()
|
||||
setUserInfoFun(res.url)
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ import { TOKEN_KEY } from '@/enums/cacheEnums'
|
|||
import cache from './cache'
|
||||
|
||||
export function getToken() {
|
||||
return cache.get(TOKEN_KEY)
|
||||
return cache.get(TOKEN_KEY) || ''
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ const cache = {
|
|||
try {
|
||||
uni.setStorageSync(key, data)
|
||||
} catch (e) {
|
||||
return null
|
||||
return undefined
|
||||
}
|
||||
},
|
||||
get(key: string) {
|
||||
|
|
@ -22,16 +22,16 @@ const cache = {
|
|||
try {
|
||||
const data = uni.getStorageSync(key)
|
||||
if (!data) {
|
||||
return null
|
||||
return undefined
|
||||
}
|
||||
const { value, expire } = JSON.parse(data)
|
||||
if (expire && expire < this.time()) {
|
||||
uni.removeStorageSync(key)
|
||||
return null
|
||||
return undefined
|
||||
}
|
||||
return value
|
||||
} catch (e) {
|
||||
return null
|
||||
return undefined
|
||||
}
|
||||
},
|
||||
//获取当前时间
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ export class RequestCancel {
|
|||
}
|
||||
add(url: string, requestTask: RequestTask) {
|
||||
this.remove(url)
|
||||
if (!cancelerMap.has(url)) {
|
||||
cancelerMap.set(url, requestTask)
|
||||
if (cancelerMap.has(url)) {
|
||||
cancelerMap.delete(url)
|
||||
}
|
||||
cancelerMap.set(url, requestTask)
|
||||
}
|
||||
remove(url: string) {
|
||||
if (cancelerMap.has(url)) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { merge } from 'lodash-es'
|
||||
import { isFunction } from '@vue/shared'
|
||||
import { HttpRequestOptions, RequestConfig, RequestOptions } from './type'
|
||||
import { RequestMethodsEnum } from '@/enums/requestEnums'
|
||||
import { HttpRequestOptions, RequestConfig, RequestOptions, UploadFileOption } from './type'
|
||||
import { RequestErrMsgEnum, RequestMethodsEnum } from '@/enums/requestEnums'
|
||||
import requestCancel from './cancel'
|
||||
|
||||
export default class HttpRequest {
|
||||
|
|
@ -9,7 +9,25 @@ export default class HttpRequest {
|
|||
constructor(options: HttpRequestOptions) {
|
||||
this.options = options
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 重新请求
|
||||
*/
|
||||
retryRequest(options: RequestOptions, config: RequestConfig) {
|
||||
const { retryCount, retryTimeout } = config
|
||||
if (!retryCount || options.method?.toUpperCase() == RequestMethodsEnum.POST) {
|
||||
return Promise.reject()
|
||||
}
|
||||
uni.showLoading({ title: '加载中...' })
|
||||
config.hasRetryCount = config.hasRetryCount ?? 0
|
||||
if (config.hasRetryCount >= retryCount) {
|
||||
return Promise.reject()
|
||||
}
|
||||
config.hasRetryCount++
|
||||
config.requestHooks.requestInterceptorsHook = (options) => options
|
||||
return new Promise((resolve) => setTimeout(resolve, retryTimeout))
|
||||
.then(() => this.request(options, config))
|
||||
.finally(() => uni.hideLoading())
|
||||
}
|
||||
/**
|
||||
* @description get请求
|
||||
*/
|
||||
|
|
@ -23,6 +41,49 @@ export default class HttpRequest {
|
|||
post<T = any>(options: RequestOptions, config?: Partial<RequestConfig>): Promise<T> {
|
||||
return this.request({ ...options, method: RequestMethodsEnum.POST }, config)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 上传图片
|
||||
*/
|
||||
uploadFile(options: UploadFileOption, config?: Partial<RequestConfig>) {
|
||||
let mergeOptions: RequestOptions = merge({}, this.options.requestOptions, options)
|
||||
const mergeConfig: RequestConfig = merge({}, this.options, config)
|
||||
const { requestInterceptorsHook, responseInterceptorsHook, responseInterceptorsCatchHook } =
|
||||
mergeConfig.requestHooks || {}
|
||||
if (requestInterceptorsHook && isFunction(requestInterceptorsHook)) {
|
||||
mergeOptions = requestInterceptorsHook(mergeOptions, mergeConfig)
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
...mergeOptions,
|
||||
success: async (response) => {
|
||||
if (response.statusCode == 200) {
|
||||
response.data = JSON.parse(response.data)
|
||||
if (responseInterceptorsHook && isFunction(responseInterceptorsHook)) {
|
||||
try {
|
||||
response = await responseInterceptorsHook(response, mergeConfig)
|
||||
resolve(response)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
return
|
||||
}
|
||||
resolve(response)
|
||||
}
|
||||
},
|
||||
fail: async (err) => {
|
||||
if (
|
||||
responseInterceptorsCatchHook &&
|
||||
isFunction(responseInterceptorsCatchHook)
|
||||
) {
|
||||
reject(await responseInterceptorsCatchHook(mergeOptions, err))
|
||||
return
|
||||
}
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* @description 请求函数
|
||||
*/
|
||||
|
|
@ -32,15 +93,15 @@ export default class HttpRequest {
|
|||
const { requestInterceptorsHook, responseInterceptorsHook, responseInterceptorsCatchHook } =
|
||||
mergeConfig.requestHooks || {}
|
||||
if (requestInterceptorsHook && isFunction(requestInterceptorsHook)) {
|
||||
mergeOptions = requestInterceptorsHook(options, mergeConfig)
|
||||
mergeOptions = requestInterceptorsHook(mergeOptions, mergeConfig)
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestTask = uni.request({
|
||||
...mergeOptions,
|
||||
success(response) {
|
||||
async success(response) {
|
||||
if (responseInterceptorsHook && isFunction(responseInterceptorsHook)) {
|
||||
try {
|
||||
response = responseInterceptorsHook(response, mergeConfig)
|
||||
response = await responseInterceptorsHook(response, mergeConfig)
|
||||
resolve(response)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
|
|
@ -49,18 +110,25 @@ export default class HttpRequest {
|
|||
}
|
||||
resolve(response)
|
||||
},
|
||||
fail(err) {
|
||||
fail: async (err) => {
|
||||
if (err.errMsg == RequestErrMsgEnum.TIMEOUT) {
|
||||
this.retryRequest(mergeOptions, mergeConfig)
|
||||
.then((res) => resolve(res))
|
||||
.catch((err) => reject(err))
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
responseInterceptorsCatchHook &&
|
||||
isFunction(responseInterceptorsCatchHook)
|
||||
) {
|
||||
reject(responseInterceptorsCatchHook(err, mergeConfig))
|
||||
reject(await responseInterceptorsCatchHook(mergeOptions, err))
|
||||
return
|
||||
}
|
||||
reject(err)
|
||||
},
|
||||
complete(err) {
|
||||
if (err.errMsg !== 'request:fail abort') {
|
||||
if (err.errMsg !== RequestErrMsgEnum.ABORT) {
|
||||
requestCancel.remove(options.url)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ import HttpRequest from './http'
|
|||
import { merge } from 'lodash-es'
|
||||
import { HttpRequestOptions, RequestHooks } from './type'
|
||||
import { getToken } from '../auth'
|
||||
import { RequestCodeEnum } from '@/enums/requestEnums'
|
||||
import { RequestCodeEnum, RequestMethodsEnum } from '@/enums/requestEnums'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { client } from '../client'
|
||||
|
||||
const requestHooks: RequestHooks = {
|
||||
requestInterceptorsHook(options, config) {
|
||||
|
|
@ -17,12 +18,15 @@ const requestHooks: RequestHooks = {
|
|||
}
|
||||
const token = getToken()
|
||||
// 添加token
|
||||
if (withToken && token) {
|
||||
options.header.token = token
|
||||
if (withToken) {
|
||||
options.header['like-token'] = options.header.token || token
|
||||
}
|
||||
// 添加终端类型
|
||||
options.header['terminal'] = client
|
||||
delete options.header.token
|
||||
return options
|
||||
},
|
||||
responseInterceptorsHook(response, config) {
|
||||
async responseInterceptorsHook(response, config) {
|
||||
const { isTransformResponse, isReturnDefaultResponse, isAuth } = config
|
||||
|
||||
//返回默认响应,当需要获取响应头及其他数据时可使用
|
||||
|
|
@ -34,7 +38,7 @@ const requestHooks: RequestHooks = {
|
|||
return response.data
|
||||
}
|
||||
const { logout } = useUserStore()
|
||||
const { code, data, msg } = response.data as any
|
||||
const { code, data, msg, show } = response.data as any
|
||||
switch (code) {
|
||||
case RequestCodeEnum.SUCCESS:
|
||||
return data
|
||||
|
|
@ -48,6 +52,7 @@ const requestHooks: RequestHooks = {
|
|||
case RequestCodeEnum.NO_PERMISSTION:
|
||||
case RequestCodeEnum.FAILED:
|
||||
case RequestCodeEnum.SYSTEM_ERROR:
|
||||
case RequestCodeEnum.REQUEST_404_ERROR:
|
||||
uni.$u.toast(msg)
|
||||
return Promise.reject(msg)
|
||||
|
||||
|
|
@ -64,6 +69,12 @@ const requestHooks: RequestHooks = {
|
|||
default:
|
||||
return data
|
||||
}
|
||||
},
|
||||
async responseInterceptorsCatchHook(options, error) {
|
||||
if (options.method?.toUpperCase() == RequestMethodsEnum.POST) {
|
||||
uni.$u.toast('请求失败,请重试')
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +94,8 @@ const defaultOptions: HttpRequestOptions = {
|
|||
// 是否携带token
|
||||
withToken: true,
|
||||
isAuth: false,
|
||||
retryCount: 2,
|
||||
retryTimeout: 1000,
|
||||
requestHooks: requestHooks
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
export type RequestOptions = UniApp.RequestOptions
|
||||
export type ResponseResult = UniApp.RequestSuccessCallbackResult
|
||||
export type ResponseError = UniApp.GeneralCallbackResult
|
||||
export type ResponseResult =
|
||||
| UniApp.RequestSuccessCallbackResult
|
||||
| UniApp.UploadFileSuccessCallbackResult
|
||||
export type RequestOptionsResponseError = UniApp.GeneralCallbackResult
|
||||
export type RequestTask = UniApp.RequestTask
|
||||
export type UploadFileOption = UniApp.UploadFileOption
|
||||
export interface HttpRequestOptions extends RequestConfig {
|
||||
requestOptions: Partial<RequestOptions>
|
||||
}
|
||||
|
|
@ -15,10 +18,13 @@ export interface RequestConfig {
|
|||
ignoreCancel: boolean
|
||||
withToken: boolean
|
||||
isAuth: boolean
|
||||
retryCount: number
|
||||
retryTimeout: number
|
||||
hasRetryCount?: number
|
||||
}
|
||||
|
||||
export interface RequestHooks {
|
||||
requestInterceptorsHook?(options: RequestOptions, config: RequestConfig): RequestOptions
|
||||
responseInterceptorsHook?(response: ResponseResult, config: RequestConfig): any
|
||||
responseInterceptorsCatchHook?(error: ResponseError, config: RequestConfig): any
|
||||
responseInterceptorsCatchHook?(options: RequestOptions, error: any): any
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { isObject } from '@vue/shared'
|
||||
import { getToken } from './auth'
|
||||
|
||||
/**
|
||||
* @description 获取元素节点信息(在组件中的元素必须要传ctx)
|
||||
|
|
@ -9,11 +8,11 @@ import { getToken } from './auth'
|
|||
*/
|
||||
export const getRect = (selector: string, all = false, context?: any) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let qurey = uni.createSelectorQuery()
|
||||
let query = uni.createSelectorQuery()
|
||||
if (context) {
|
||||
qurey = uni.createSelectorQuery().in(context)
|
||||
query = uni.createSelectorQuery().in(context)
|
||||
}
|
||||
qurey[all ? 'selectAll' : 'select'](selector)
|
||||
query[all ? 'selectAll' : 'select'](selector)
|
||||
.boundingClientRect(function (rect) {
|
||||
if (all && Array.isArray(rect) && rect.length) {
|
||||
return resolve(rect)
|
||||
|
|
@ -94,35 +93,3 @@ export function objectToQuery(params: Record<string, any>): string {
|
|||
}
|
||||
return query.slice(0, -1)
|
||||
}
|
||||
/**
|
||||
* @description 上传图片
|
||||
* @param { String } path 选择的本地地址
|
||||
*/
|
||||
export function uploadFile(path: any) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const token = getToken()
|
||||
uni.uploadFile({
|
||||
url: `${import.meta.env.VITE_APP_BASE_URL}/api/upload/image`,
|
||||
filePath: path,
|
||||
name: 'file',
|
||||
header: {
|
||||
token
|
||||
},
|
||||
fileType: 'image',
|
||||
success: (res) => {
|
||||
console.log('uploadFile res ==> ', res)
|
||||
const data = JSON.parse(res.data)
|
||||
console.log('data.code', data.code)
|
||||
if (data.code == 200) {
|
||||
resolve(data.data)
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log(err)
|
||||
reject()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue