更新:增加课程和图书VIP购买及“我的”主页vip身份显示
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { t } from '@/utils/i18n'
|
||||
/**
|
||||
* 页面跳转
|
||||
* @param {string} path - 要跳转的页面路径
|
||||
*/
|
||||
export const onPageJump = (path: string) => {
|
||||
uni.navigateTo({
|
||||
@@ -17,6 +18,8 @@ export const onPageBack = () => {
|
||||
|
||||
/**
|
||||
* 拨打电话
|
||||
* @param {string} phoneNumber - 要拨打的电话号码
|
||||
* @param {string} title - 拨打电话提示的标题,默认值为空字符串
|
||||
*/
|
||||
export const makePhoneCall = (phoneNumber: string, title: string = '') => {
|
||||
uni.showModal({
|
||||
@@ -42,6 +45,8 @@ export const makePhoneCall = (phoneNumber: string, title: string = '') => {
|
||||
|
||||
/**
|
||||
* 复制到剪贴板
|
||||
* @param {string} content - 要复制的内容
|
||||
* @param {string} title - 复制成功提示的标题,默认值为空字符串
|
||||
*/
|
||||
export const copyToClipboard = (content: string, title: string = '') => {
|
||||
uni.setClipboardData({
|
||||
@@ -60,6 +65,8 @@ export const copyToClipboard = (content: string, title: string = '') => {
|
||||
|
||||
/**
|
||||
* 计算最低价格
|
||||
* @param {object} priceData - 价格数据对象,键为价格类型,值为价格
|
||||
* @returns {object} - 包含最低价格的键值对,{ key: 价格类型, value: 最低价格 }
|
||||
*/
|
||||
export const calculateLowestPrice = (priceData: object): { key: string, value: number } => {
|
||||
const validEntries = Object.entries(priceData)
|
||||
@@ -74,4 +81,52 @@ export const calculateLowestPrice = (priceData: object): { key: string, value: n
|
||||
);
|
||||
|
||||
return { key: minKey, value: minValue };
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the time to string
|
||||
* @param {(Object|string|number)} time
|
||||
* @param {string} cFormat
|
||||
* @returns {string | null}
|
||||
*/
|
||||
export function parseTime(time: any, cFormat: string) {
|
||||
if (arguments.length === 0 || !time) {
|
||||
return null
|
||||
}
|
||||
const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
|
||||
let date
|
||||
if (typeof time === 'object') {
|
||||
date = time
|
||||
} else {
|
||||
if ((typeof time === 'string')) {
|
||||
if ((/^[0-9]+$/.test(time))) {
|
||||
// support "1548221490638"
|
||||
time = parseInt(time)
|
||||
} else {
|
||||
// support safari
|
||||
time = time.replace(new RegExp(/-/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(/{([ymdhisa])+}/g, (result, key) => {
|
||||
const value = formatObj[key as keyof typeof formatObj]
|
||||
// Note: getDay() returns 0 on Sunday
|
||||
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value as number] }
|
||||
return value.toString().padStart(2, '0')
|
||||
})
|
||||
return time_str
|
||||
}
|
||||
Reference in New Issue
Block a user