213 lines
6.9 KiB
JavaScript
213 lines
6.9 KiB
JavaScript
/**
|
|
* Purpose: toIdString supports format.js by holding or executing the to id string page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function toIdString(value) {
|
|
return value === undefined || value === null ? '' : String(value)
|
|
}
|
|
|
|
/**
|
|
* Purpose: sameId supports format.js by holding or executing the same id page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function sameId(left, right) {
|
|
return toIdString(left) === toIdString(right)
|
|
}
|
|
|
|
/**
|
|
* Purpose: splitCsv supports format.js by holding or executing the split csv page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function splitCsv(value) {
|
|
return String(value || '')
|
|
.split(',')
|
|
.map(item => item.trim())
|
|
.filter(Boolean)
|
|
}
|
|
|
|
/**
|
|
* Purpose: formatPrice supports format.js by holding or executing the format price page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function formatPrice(value) {
|
|
return Number(value || 0).toFixed(2)
|
|
}
|
|
|
|
/**
|
|
* Purpose: formatDateTime supports format.js by holding or executing the format date time page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function formatDateTime(value) {
|
|
if (!value) {
|
|
return ''
|
|
}
|
|
|
|
return String(value).replace('T', ' ').slice(0, 16)
|
|
}
|
|
|
|
/**
|
|
* Purpose: formatDate supports format.js by holding or executing the format date page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function formatDate(value) {
|
|
return formatDateTime(value).slice(0, 10)
|
|
}
|
|
|
|
/**
|
|
* Purpose: maskPhone supports format.js by holding or executing the mask phone page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function maskPhone(phone) {
|
|
const value = String(phone || '')
|
|
if (value.length !== 11) {
|
|
return value
|
|
}
|
|
return `${value.slice(0, 3)}****${value.slice(7)}`
|
|
}
|
|
|
|
/**
|
|
* Purpose: truncateText supports format.js by holding or executing the truncate text page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function truncateText(value, limit) {
|
|
const text = String(value || '')
|
|
if (!limit || text.length <= limit) {
|
|
return text
|
|
}
|
|
return `${text.slice(0, limit)}...`
|
|
}
|
|
|
|
/**
|
|
* Purpose: buildShopName supports format.js by holding or executing the build shop name page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function buildShopName(record) {
|
|
if (!record) {
|
|
return '未绑定店铺'
|
|
}
|
|
|
|
if (Array.isArray(record.shopNames) && record.shopNames.length) {
|
|
return record.shopNames.join(' / ')
|
|
}
|
|
|
|
if (record.shopName) {
|
|
return record.shopName
|
|
}
|
|
|
|
return '未绑定店铺'
|
|
}
|
|
|
|
/**
|
|
* Purpose: getUserStatusText supports format.js by holding or executing the get user status text page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function getUserStatusText(status) {
|
|
return Number(status) === 0 ? '已停用' : '正常'
|
|
}
|
|
|
|
/**
|
|
* Purpose: getUserTypeText supports format.js by holding or executing the get user type text page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function getUserTypeText(type) {
|
|
const value = Number(type)
|
|
if (value === 4) {
|
|
return '平台管理员'
|
|
}
|
|
if (value === 2) {
|
|
return '店长'
|
|
}
|
|
if (value === 3) {
|
|
return '美甲师'
|
|
}
|
|
return '普通用户'
|
|
}
|
|
|
|
/**
|
|
* Purpose: getOrderStatusText supports format.js by holding or executing the get order status text page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function getOrderStatusText(order) {
|
|
if (order && order.statusText) {
|
|
return order.statusText
|
|
}
|
|
|
|
const status = Number(order && order.status)
|
|
if (status === 1) {
|
|
return '待服务'
|
|
}
|
|
if (status === 2) {
|
|
return '已完成'
|
|
}
|
|
return '已取消'
|
|
}
|
|
|
|
/**
|
|
* Purpose: getCouponTypeText supports format.js by holding or executing the get coupon type text page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function getCouponTypeText(type) {
|
|
return Number(type) === 1 ? '折扣券' : '满减券'
|
|
}
|
|
|
|
/**
|
|
* Purpose: getCouponValueText supports format.js by holding or executing the get coupon value text page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function getCouponValueText(coupon) {
|
|
if (Number(coupon && coupon.couponType) === 1) {
|
|
return `${coupon && coupon.discountValue ? coupon.discountValue : '--'} 折`
|
|
}
|
|
return `满 ${formatPrice(coupon && coupon.minAmount)} 减 ${formatPrice(coupon && coupon.reduceAmount)}`
|
|
}
|
|
|
|
/**
|
|
* Purpose: parseDateTimeToPicker supports format.js by holding or executing the parse date time to picker page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function parseDateTimeToPicker(value) {
|
|
const text = formatDateTime(value)
|
|
if (!text) {
|
|
return {
|
|
date: '',
|
|
time: ''
|
|
}
|
|
}
|
|
|
|
const parts = text.split(' ')
|
|
return {
|
|
date: parts[0] || '',
|
|
time: (parts[1] || '').slice(0, 5)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Purpose: buildDateTime supports format.js by holding or executing the build date time page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function buildDateTime(date, time) {
|
|
if (!date || !time) {
|
|
return ''
|
|
}
|
|
return `${date} ${time}:00`
|
|
}
|
|
|
|
module.exports = {
|
|
toIdString,
|
|
sameId,
|
|
splitCsv,
|
|
formatPrice,
|
|
formatDateTime,
|
|
formatDate,
|
|
maskPhone,
|
|
truncateText,
|
|
buildShopName,
|
|
getUserStatusText,
|
|
getUserTypeText,
|
|
getOrderStatusText,
|
|
getCouponTypeText,
|
|
getCouponValueText,
|
|
parseDateTimeToPicker,
|
|
buildDateTime
|
|
}
|