This commit is contained in:
dzc committed 2024-11-11 14:42:47 +08:00
commit 7d450caf77
146 files changed
+39809

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
export * from "./use-page";
export * from "./use-unit";
+78
View File
@@ -0,0 +1,78 @@
import { reactive, onMounted } from "vue";
export const usePage = (
ref: any = null,
fn: Function | null = null,
sticky = null,
struct = "data"
) => {
const state = reactive<any>({
loading: true,
list: [],
headerHeight: 0,
scrollable: true,
});
const scroll = (e: any) => {
const scrollTop = e.detail.scrollTop;
if (scrollTop < state.headerHeight) {
state.scrollable = true;
} else {
state.scrollable = false;
}
};
onMounted(() => {
if (sticky != null) {
const query = uni.createSelectorQuery();
query
.select(sticky)
.boundingClientRect((data) => {
state.headerHeight = (data as any).height;
})
.exec();
}
});
const setPage = async (list: Array<any>) => {
if (ref == null) return;
state.list.totalList = await ref.value.complete(list);
console.log(state.list, "list");
};
const startPage = async (
page: number,
pagesize: number,
isPage = false,
query = {}
) => {
if (!fn || typeof fn !== "function") {
console.warn("startPage 方法请传入 pageFunc 参数 模拟5条假数据");
state.list = Array.from(new Array(5));
setPage(state.list);
state.startPage = startPage;
state.scroll = scroll;
return state;
}
const _data = {
pageNo: page,
pagesize: pagesize,
...query,
};
try {
const res = await fn(_data);
let _arr = res;
for (let key of struct.split(".")) {
_arr = _arr[key];
}
setPage(_arr);
} catch (e) {
console.log(e);
}
setTimeout((_) => {
if (state.loading == true) {
state.loading = false;
}
}, 500);
};
state.startPage = startPage;
state.scroll = scroll;
return state;
};
+49
View File
@@ -0,0 +1,49 @@
export const useMoney = (num) => {
if (typeof num === "undefined") return "0.00";
const parsedNumber = typeof num === "string" ? parseFloat(num) : num;
return (parsedNumber / 100.0).toFixed(1);
};
export function useTime(time, pattern) {
if (arguments.length === 0 || !time) {
return null;
}
const format = pattern || "{y}-{m}-{d} {h}:{i}:{s}";
let date;
if (typeof time === "object") {
date = time;
} else {
if (typeof time === "string" && /^[0-9]+$/.test(time)) {
time = parseInt(time);
} else if (typeof time === "string") {
time = time
.replace(new RegExp(/-/gm), "/")
.replace("T", " ")
.replace(new RegExp(/\.[\d]{3}/gm), "");
}
if (typeof time === "number" && time.toString().length === 10) {
time = time * 1000;
}
date = new Date(time);
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay(),
};
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key];
if (key === "a") {
return ["日", "一", "二", "三", "四", "五", "六"][value];
}
if (result.length > 0 && value < 10) {
value = "0" + value;
}
return value || 0;
});
return time_str;
}