初始化项目

This commit is contained in:
2026-09-01 22:15:50 +08:00
commit b5a26a8848
11217 changed files with 1710987 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
import paginate from './paginate'
export { paginate }
@@ -0,0 +1,7 @@
export default {
data: [], // 列表数据
current_page: 1, // 当前页码
last_page: 1, // 最大页码
per_page: 15, // 每页记录数
total: 0, // 总记录数
}
@@ -0,0 +1,10 @@
import Enum from '../enum'
/**
* 枚举类:优惠券适用范围
* ApplyRangeEnum
*/
export default new Enum([
{ key: 'ALL', name: '全部商品', value: 10 },
{ key: 'SOME_GOODS', name: '指定商品', value: 20 }
])
@@ -0,0 +1,10 @@
import Enum from '../enum'
/**
* 枚举类:优惠券类型
* CouponTypeEnum
*/
export default new Enum([
{ key: 'FULL_DISCOUNT', name: '满减券', value: 10 },
{ key: 'DISCOUNT', name: '折扣券', value: 20 }
])
@@ -0,0 +1,10 @@
import Enum from '../enum'
/**
* 枚举类:优惠券到期类型
* ExpireTypeEnum
*/
export default new Enum([
{ key: 'RECEIVE', name: '领取后', value: 10 },
{ key: 'FIXED_TIME', name: '固定时间', value: 20 }
])
@@ -0,0 +1,5 @@
import ApplyRangeEnum from './ApplyRange'
import ExpireTypeEnum from './ExpireType'
import CouponTypeEnum from './CouponType'
export { ApplyRangeEnum, CouponTypeEnum, ExpireTypeEnum }
+85
View File
@@ -0,0 +1,85 @@
/**
* 枚举类
* Enum.IMAGE.name => "图片"
* Enum.getNameByKey('IMAGE') => "图片"
* Enum.getValueByKey('IMAGE') => 10
* Enum.getNameByValue(10) => "图片"
* Enum.getData() => [{key: "IMAGE", name: "图片", value: 10}]
*/
class Enum {
constructor (param) {
const keyArr = []
const valueArr = []
if (!Array.isArray(param)) {
throw new Error('param is not an array!')
}
param.map(element => {
if (!element.key || !element.name) {
return
}
// 保存key值组成的数组,方便A.getName(name)类型的调用
keyArr.push(element.key)
valueArr.push(element.value)
// 根据key生成不同属性值,以便A.B.name类型的调用
this[element.key] = element
if (element.key !== element.value) {
this[element.value] = element
}
})
// 保存源数组
this.data = param
this.keyArr = keyArr
this.valueArr = valueArr
// 防止被修改
// Object.freeze(this)
}
// 根据key得到对象
keyOf (key) {
return this.data[this.keyArr.indexOf(key)]
}
// 根据key得到对象
valueOf (key) {
return this.data[this.valueArr.indexOf(key)]
}
// 根据key获取name值
getNameByKey (key) {
const prop = this.keyOf(key)
if (!prop) {
throw new Error('No enum constant' + key)
}
return prop.name
}
// 根据value获取name值
getNameByValue (value) {
const prop = this.valueOf(value)
if (!prop) {
throw new Error('No enum constant' + value)
}
return prop.name
}
// 根据key获取value值
getValueByKey (key) {
const prop = this.keyOf(key)
if (!prop) {
throw new Error('No enum constant' + key)
}
return prop.key
}
// 返回源数组
getData () {
return this.data
}
}
export default Enum
@@ -0,0 +1,10 @@
import Enum from '../enum'
/**
* 枚举类:商品规格类型
* SpecTypeEnum
*/
export default new Enum([
{ key: 'SINGLE', name: '单规格', value: 10 },
{ key: 'MULTI', name: '多规格', value: 20 }
])
+3
View File
@@ -0,0 +1,3 @@
import SpecTypeEnum from './SpecType'
export { SpecTypeEnum }
@@ -0,0 +1,10 @@
import Enum from '../enum'
/**
* 枚举类:订单发货状态
* DeliveryStatusEnum
*/
export default new Enum([
{ key: 'NOT_DELIVERED', name: '未发货', value: 10 },
{ key: 'DELIVERED', name: '已发货', value: 20 }
])
@@ -0,0 +1,9 @@
import Enum from '../enum'
/**
* 枚举类:配送方式
* DeliveryTypeEnum
*/
export default new Enum([
{ key: 'EXPRESS', name: '快递配送', value: 10 }
])
@@ -0,0 +1,11 @@
import Enum from '../enum'
/**
* 枚举类:订单来源
* OrderSourceEnum
*/
export default new Enum([
{ key: 'MASTER', name: '普通订单', value: 10 },
{ key: 'BARGAIN', name: '砍价订单', value: 20 },
{ key: 'SHARP', name: '秒杀订单', value: 30 }
])
@@ -0,0 +1,12 @@
import Enum from '../enum'
/**
* 枚举类:订单状态
* OrderStatusEnum
*/
export default new Enum([
{ key: 'NORMAL', name: '进行中', value: 10 },
{ key: 'CANCELLED', name: '已取消', value: 20 },
{ key: 'APPLY_CANCEL', name: '待取消', value: 21 },
{ key: 'COMPLETED', name: '已完成', value: 30 }
])
@@ -0,0 +1,10 @@
import Enum from '../enum'
/**
* 枚举类:订单支付状态
* PayStatusEnum
*/
export default new Enum([
{ key: 'PENDING', name: '待支付', value: 10 },
{ key: 'SUCCESS', name: '已支付', value: 20 }
])
@@ -0,0 +1,10 @@
import Enum from '../enum'
/**
* 枚举类:订单支付方式
* PayTypeEnum
*/
export default new Enum([
{ key: 'BALANCE', name: '余额支付', value: 10 },
{ key: 'WECHAT', name: '微信支付', value: 20 }
])
@@ -0,0 +1,10 @@
import Enum from '../enum'
/**
* 枚举类:订单收货状态
* ReceiptStatusEnum
*/
export default new Enum([
{ key: 'NOT_RECEIVED', name: '未收货', value: 10 },
{ key: 'RECEIVED', name: '已收货', value: 20 }
])
+17
View File
@@ -0,0 +1,17 @@
import DeliveryStatusEnum from './DeliveryStatus'
import DeliveryTypeEnum from './DeliveryType'
import OrderSourceEnum from './OrderSource'
import OrderStatusEnum from './OrderStatus'
import PayStatusEnum from './PayStatus'
import PayTypeEnum from './PayType'
import ReceiptStatusEnum from './ReceiptStatus'
export {
DeliveryStatusEnum,
DeliveryTypeEnum,
OrderSourceEnum,
OrderStatusEnum,
PayStatusEnum,
PayTypeEnum,
ReceiptStatusEnum
}
@@ -0,0 +1,11 @@
import Enum from '../../enum'
/**
* 枚举类:商家审核状态
* AuditStatusEnum
*/
export default new Enum([
{ key: 'WAIT', name: '待审核', value: 0 },
{ key: 'REVIEWED', name: '已同意', value: 10 },
{ key: 'REJECTED', name: '已拒绝', value: 20 }
])
@@ -0,0 +1,12 @@
import Enum from '../../enum'
/**
* 枚举类:售后单状态
* RefundStatusEnum
*/
export default new Enum([
{ key: 'NORMAL', name: '进行中', value: 0 },
{ key: 'REJECTED', name: '已拒绝', value: 10 },
{ key: 'COMPLETED', name: '已完成', value: 20 },
{ key: 'CANCELLED', name: '已取消', value: 30 }
])
@@ -0,0 +1,10 @@
import Enum from '../../enum'
/**
* 枚举类:售后类型
* RefundTypeEnum
*/
export default new Enum([
{ key: 'RETURN', name: '退货退款', value: 10 },
{ key: 'EXCHANGE', name: '换货', value: 20 }
])
@@ -0,0 +1,9 @@
import AuditStatusEnum from './AuditStatus'
import RefundStatusEnum from './RefundStatus'
import RefundTypeEnum from './RefundType'
export {
AuditStatusEnum,
RefundStatusEnum,
RefundTypeEnum
}
+42
View File
@@ -0,0 +1,42 @@
import Enum from '../enum'
/**
* 枚举类:设置项索引
* SettingKeyEnum
*/
export default new Enum([{
key: 'REGISTER',
name: '账户注册设置',
value: 'register'
},
{
key: 'PAGE_CATEGORY_TEMPLATE',
name: '分类页模板',
value: 'page_category_template'
},
{
key: 'POINTS',
name: '积分设置',
value: 'points'
},
{
key: 'RECHARGE',
name: '充值设置',
value: 'recharge'
},
{
key: 'EXCHANGE',
name: '兑换设置',
value: 'exchange'
},
{
key: 'SHARE',
name: '分享设置',
value: 'share'
},
{
key: 'TRADE',
name: '商城设置',
value: 'trade'
}
])
@@ -0,0 +1,12 @@
import Enum from '../../../enum'
/**
* 枚举类:地址类型
* PageCategoryStyleEnum
*/
export default new Enum([
{ key: 'ONE_LEVEL_BIG', name: '一级分类[大图]', value: 10 },
{ key: 'ONE_LEVEL_SMALL', name: '一级分类[小图]', value: 11 },
{ key: 'TWO_LEVEL', name: '二级分类', value: 20 },
{ key: 'COMMODITY', name: '一级分类+商品', value: 30 }
])
@@ -0,0 +1,3 @@
import PageCategoryStyleEnum from './Style'
export { PageCategoryStyleEnum }
+57
View File
@@ -0,0 +1,57 @@
import * as Api from '@/api/region'
import storage from '@/utils/storage'
const REGION_TREE = 'region_tree'
/**
* 商品分类 model类
* RegionModel
*/
export default {
// 从服务端获取全部地区数据(树状)
getTreeDataFromApi () {
return new Promise((resolve, reject) => {
Api.tree().then(result => resolve(result.data.list))
})
},
// 获取所有地区(树状)
getTreeData () {
return new Promise((resolve, reject) => {
// 判断缓存中是否存在
const data = storage.get(REGION_TREE)
// 从服务端获取全部地区数据
if (data) {
resolve(data)
} else {
this.getTreeDataFromApi().then(list => {
// 缓存24小时
storage.set(REGION_TREE, list, 24 * 60 * 60)
resolve(list)
})
}
})
},
// 获取所有地区的总数
getCitysCount () {
return new Promise((resolve, reject) => {
// 获取所有地区(树状)
this.getTreeData().then(data => {
const cityIds = []
// 遍历省份
for (const pidx in data) {
const province = data[pidx]
// 遍历城市
for (const cidx in province.city) {
const cityItem = province.city[cidx]
cityIds.push(cityItem.id)
}
}
resolve(cityIds.length)
})
})
}
}
+77
View File
@@ -0,0 +1,77 @@
import Config from '@/core/config'
import storage from '@/utils/storage'
import * as SettingApi from '@/api/setting'
const CACHE_KEY = 'Setting'
const OTHER = '_other'
// 写入缓存, 到期时间10分钟
const setStorage = (data) => {
const expireTime = 10 * 60
storage.set(CACHE_KEY, data, expireTime)
}
// 获取缓存中的数据
const getStorage = () => {
return storage.get(CACHE_KEY)
}
// 获取后端接口商城设置 (最新)
const getApiData = () => {
return new Promise((resolve, reject) => {
SettingApi.data()
.then(result => {
resolve(result.data.setting)
})
})
}
/**
* 获取商城设置
* 有缓存的情况下返回缓存, 没有缓存从后端api获取
* @param {bool} isCache 是否从缓存中获取 [优点不用每次请求后端api 缺点后台更新设置后需等待时效性]
*/
const data = isCache => {
if (isCache == undefined) {
isCache = Config.get('enabledSettingCache')
}
return new Promise((resolve, reject) => {
const cacheData = getStorage()
if (isCache && cacheData) {
resolve(cacheData)
} else {
getApiData()
.then(data => {
setStorage(data)
resolve(data)
})
}
})
}
// 获取商城设置(指定项)
const item = (key, isCache) => {
return new Promise((resolve, reject) => {
data(isCache)
.then(setting => {
resolve(setting[key])
})
})
}
// 获取H5端访问地址
const h5Url = (isCache = false) => {
return new Promise((resolve, reject) => {
data(isCache)
.then(setting => {
const h5Url = setting[OTHER]['h5Url']
resolve(h5Url)
})
})
}
export default {
data,
item,
h5Url
}