| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- // 导入请求
- import { request } from '../request.uts'
- // 基础 URL 配置
- // #ifdef APP-ANDROID
- const BASE_URL = 'https://dev.xiaodingyun.cn'
- // #endif
- // #ifdef APP-IOS
- const BASE_URL = 'https://dev.xiaodingyun.cn'
- // #endif
- // #ifdef H5
- const BASE_URL = ''
- // #endif
- // #ifdef MP-WEIXIN
- const BASE_URL = 'https://dev.xiaodingyun.cn'
- // #endif
- // #ifdef MP-HARMONY
- const BASE_URL = 'https://dev.xiaodingyun.cn'
- // #endif
- export function getAllData(params : any) : Promise<any> {
- return request({
- url: `${BASE_URL}/api/coach/v3/orders/statistics`,
- method: "GET",
- params: params
- })
- }
- export function editCoachWorkState(data : any) : Promise<any> {
- return request({
- url: `${BASE_URL}/api/coach/v3/account/work-status`,
- method: "POST",
- data: data
- })
- }
- export function editWorkTimeSetting(data : any) : Promise<any> {
- return request({
- url: `${BASE_URL}/api/coach/v3/account/schedule`,
- method: "POST",
- data: data
- })
- }
- export function toggleProject(data : any) : Promise<any> {
- return request({
- url: `${BASE_URL}/api/coach/v3/projects/open`,
- method: "POST",
- data: data
- })
- }
- import { makePhoneCall } from "./location";
- /**
- * 拨打电话
- * @param {string} phoneNumber - 电话号码
- */
- export const navigateToMobile = (phoneNumber : String) => {
- makePhoneCall(phoneNumber ?? '4000678313');
- };
- /**
- * @description 防抖函数
- * @param {Function} fn - 需要防抖的函数
- * @param {number} delay - 延迟时间,默认1000ms
- * @returns {Function} - 防抖后的函数
- */
- export const debounce = (fn : Function, delay : number = 2000) : Function => {
- let timer : number | null = null
- return function (...args : any[]) {
- if (timer) clearTimeout(timer)
- timer = setTimeout(() => {
- fn.apply(this, args)
- }, delay)
- }
- }
- /**
- * @description 节流函数
- * @param {Function} fn - 需要节流的函数
- * @param {number} delay - 延迟时间,默认1000ms
- * @returns {Function} - 节流后的函数
- */
- export const throttle = (fn : Function, delay : number = 300) : Function => {
- let timer : number | null = null
- let start : number = Date.now()
- return function (...args : any[]) {
- const current : number = Date.now()
- const remaining : number = delay - (current - start)
- clearTimeout(timer!)
- if (remaining <= 0) {
- fn.apply(this, args)
- start = Date.now()
- } else {
- timer = setTimeout(() => {
- fn.apply(this, args)
- start = Date.now()
- }, remaining)
- }
- }
- }
- // 缓存相关工具函数
- export const cacheTools = {
- // 获取缓存
- get(key : string) : any | null { // 显式声明参数类型和返回类型
- try {
- const data = uni.getStorageSync(key) as UTSJSONObject | null // 类型断言
- if (data == null) return null
- // 检查缓存是否过期(5分钟)
- const timestamp = data['timestamp'] as number // 通过索引访问并断言类型
- if (Date.now() - timestamp > 5 * 60 * 1000) {
- uni.removeStorageSync(key)
- return null
- }
- return data
- } catch (e) {
- return null
- }
- },
- // 设置缓存
- set(key : string, value : any) : void { // 显式声明参数类型
- try {
- uni.setStorageSync(key, {
- data: value,
- timestamp: Date.now()
- })
- } catch (e) {
- console.error('缓存设置失败', e)
- }
- }
- }
- // 网络状态检测
- export const checkNetwork = () => {
- return new Promise((resolve) => {
- uni.getNetworkType({
- success: (res) => {
- resolve(res.networkType !== "none");
- },
- fail: () => {
- resolve(false);
- },
- });
- });
- };
- /**
- * 格式化日期
- * @param {Date} date - 要格式化的日期对象
- * @param {string} fmt - 格式化模板,如 'YYYY-MM-DD HH:mm:ss'
- * @returns {string} 格式化后的日期字符串
- */
- export const formatDate = (date : any, fmt : string) : string => {
- if (!date) return "";
- if (typeof date === "string") {
- date = new Date(date.replace(/-/g, "/"));
- }
- if (typeof date === "number") {
- date = new Date(date);
- }
- const o = {
- "M+": date.getMonth() + 1,
- "D+": date.getDate(),
- "H+": date.getHours(),
- "m+": date.getMinutes(),
- "s+": date.getSeconds(),
- "q+": Math.floor((date.getMonth() + 3) / 3),
- S: date.getMilliseconds(),
- };
- if (/(Y+)/.test(fmt)) {
- fmt = fmt.replace(
- RegExp.$1,
- (date.getFullYear() + "").substr(4 - RegExp.$1.length)
- );
- }
- for (let k in o) {
- if (new RegExp("(" + k + ")").test(fmt)) {
- fmt = fmt.replace(
- RegExp.$1,
- RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
- );
- }
- }
- return fmt;
- };
- //最新上传图片2025-02-17
- export async function newUploadImage(
- bucket : string = "photo-images",
- module : string = "real-photo"
- ) : Promise<any> {
- return new Promise((resolve, reject) => {
- uni.chooseImage({
- count: 1,
- success: (res) => {
- const tempFilePaths = res.tempFilePaths
- uni.showLoading({
- title: "上传中...",
- mask: true,
- })
- uni.uploadFile({
- url: "https://dev.xiaodingyun.cn/api/upload",
- filePath: tempFilePaths[0],
- name: "file",
- formData: {
- bucket: bucket,
- module: module,
- },
- success: (uploadFileRes) => {
- let data = JSON.parse(uploadFileRes.data) as UTSJSONObject
- if (data['code'] as number == 200) {
- resolve({ code: 200, data: data['data'], message: "上传成功" })
- } else {
- reject({ code: 202, data: {}, message: "上传失败" })
- }
- },
- fail: (err) => {
- reject({ code: 202, data: {}, message: "上传失败" })
- },
- complete: () => {
- uni.hideLoading()
- },
- })
- },
- fail: (err) => {
- reject({ code: 202, data: {}, message: "上传失败" })
- },
- })
- })
- }
- //汇付天下
- export const huifuUpload = async () => {
- //获取token
- const token = await uni.getStorageSync("token");
- return new Promise((resolve, reject) => {
- uni.chooseImage({
- count: 1,
- fileType: "image",
- success: (res) => {
- const tempFilePaths = res.tempFilePaths;
- uni.showLoading({
- title: "上传中...",
- mask: true,
- });
- uni.uploadFile({
- url: "https://dev.xiaodingyun.cn/api/coach/v3/wallet/BsUpload",
- filePath: tempFilePaths[0],
- name: "file",
- header: {
- Authorization: "Bearer " + token,
- },
- success: (uploadFileRes) => {
- let data = JSON.parse(uploadFileRes.data);
- if (data.code == 200) {
- resolve({ code: 200, data: data.data, message: "上传成功" });
- } else {
- reject({ code: 202, data: {}, message: "上传失败" });
- }
- },
- fail: (err) => {
- reject({ code: 202, data: {}, message: "上传失败" });
- },
- complete: () => {
- uni.hideLoading();
- },
- });
- },
- fail: (err) => {
- reject({ code: 202, data: {}, message: "上传失败" });
- },
- });
- });
- };
|