|
3 days ago | |
---|---|---|
api | 4 days ago | |
components | 4 days ago | |
doc | 2 months ago | |
mixins | 5 days ago | |
pages/index | 4 days ago | |
pages_order | 3 days ago | |
static/image | 1 month ago | |
store | 4 days ago | |
uni_modules | 1 month ago | |
utils | 6 days ago | |
.gitignore | 2 months ago | |
App.vue | 4 days ago | |
README.md | 5 days ago | |
common.scss | 2 months ago | |
config.js | 1 month ago | |
index.html | 2 months ago | |
main.js | 2 months ago | |
manifest.json | 6 days ago | |
package.json | 1 month ago | |
pages.json | 5 days ago | |
uni.promisify.adaptor.js | 2 months ago | |
uni.scss | 1 month ago |
本项目是一个基于uni-app开发的珠宝商城小程序,采用Vue框架开发,集成了完整的商城功能模块。
├── api # API接口目录
│ ├── api.js # API统一出口
│ ├── http.js # HTTP请求封装
│ └── model # 业务模块API
├── components # 公共组件
├── mixins # 混入文件
├── pages # 页面文件
├── static # 静态资源
├── store # Vuex状态管理
├── utils # 工具函数
└── uni_modules # uni-app插件模块
分包是小程序优化加载性能的重要手段,pages_order作为独立分包,包含以下模块:
├── auth # 认证相关页面
│ ├── loginAndRegisterAndForgetPassword.vue # 登录注册
│ ├── wxLogin.vue # 微信登录
│ └── wxUserInfo.vue # 微信用户信息
├── components # 分包内公共组件
│ ├── address/ # 地址选择组件
│ ├── areaSelector/ # 区域选择器
│ └── product/ # 商品相关组件
├── home # 首页相关
│ ├── addEnterprise.vue # 添加企业
│ ├── contact.vue # 联系我们
│ ├── introduce.vue # 介绍页面
│ ├── journalism.vue # 新闻资讯
│ └── notice.vue # 公告
├── mine # 我的模块
│ ├── address.vue # 收货地址
│ ├── balance.vue # 余额
│ ├── commission.vue # 佣金
│ ├── coupon.vue # 优惠券
│ ├── memberCenter.vue # 会员中心
│ └── more... # 更多功能页面
├── order # 订单模块
│ ├── createOrder.vue # 创建订单
│ ├── orderDetail.vue # 订单详情
│ └── giftList.vue # 礼品列表
├── product # 商品模块
│ └── productDetail.vue # 商品详情
└── static # 分包静态资源
├── address/ # 地址相关图片
├── auth/ # 认证相关图片
├── coupon/ # 优惠券图片
└── more... # 其他静态资源
分包特点:
项目核心配置文件,包含以下配置:
1. 环境配置
// 当前环境
const type = 'prod'
// 环境配置
const config = {
dev: {
baseUrl: 'http://h5.xzaiyp.top/jewelry-admin',
},
prod: {
baseUrl: 'https://jewelry-admin.hhlm1688.com/jewelry-admin',
}
}
2. 默认配置
const defaultConfig = {
// 腾讯地图Key
mapKey: 'XMBBZ-BCPCV-SXPPQ-5Y7MY-PHZXK-YFFVU',
// 阿里云OSS配置
aliOss: {
url: 'https://image.hhlm1688.com/',
config: {
region: 'oss-cn-guangzhou',
accessKeyId: '***',
accessKeySecret: '***',
bucket: 'hanhaiimage',
endpoint: 'oss-cn-shenzhen.aliyuncs.com',
}
}
}
3. UI框架配置
uni.$uv.setConfig({
config: {
unit: 'rpx' // 设置默认单位
},
})
提供列表数据的加载、分页、下拉刷新、上拉加载更多等功能。
主要功能:
使用示例:
// 在页面中使用list混入
import listMixin from '@/mixins/list.js'
export default {
mixins: [listMixin],
data() {
return {
// 指定API接口
mixinsListApi: 'product.list'
}
}
}
已全局引入的配置管理混入,无需手动引入即可使用。
主要功能:
配置参数:
// 分享配置示例
this.Gshare.title = '分享标题'
this.Gshare.path = '分享路径'
统一的HTTP请求处理,包含:
统一管理API接口,支持模块化组织。API模块采用分层结构,便于维护和扩展。
目录结构:
api/
├── api.js # API统一出口
├── http.js # HTTP请求封装
└── model/ # 业务模块API
├── product.js # 商品相关接口
├── order.js # 订单相关接口
└── user.js # 用户相关接口
接口定义示例:
// api/model/product.js
export default {
// GET请求示例
list: {
url: '/api/product/list',
method: 'GET',
loading: true // 显示加载提示
},
// POST请求示例
create: {
url: '/api/product/create',
method: 'POST',
loading: true // 显示加载提示
auth : true,//效验登录
debounce : 1000,//接口防抖,1s
limit : 500,//接口限流,0.5s
},
}
调用接口示例:
// 第一种写法:callback方式处理响应
this.$api('product.list', {
pageNo: 1,
pageSize: 10,
categoryId: '123'
}, res => {
// 处理列表数据
})
// 第二种写法:Promise方式处理响应
this.$api('product.create', {
name: '商品名称',
price: 99.99,
description: '商品描述'
}).then(res => {
if (res.code === 200) {
// 创建成功
uni.showToast({ title: '创建成功' })
}
})
使用示例:
// 授权处理
async preservationImg(img) {
await this.$authorize('scope.writePhotosAlbum')
//在执行$authorize之后,await下面的代码都是确保授权完成的情况下执行
},
// 时间格式化
const formattedTime = this.$timeUtils.formatTime(new Date())
// 微信网页支付调用
import { wxPay } from '@/utils/pay'
wxPay(orderData)
使用示例:
<template>
<view>
<navbar title="商品列表" />
<product-item
v-for="item in list"
:key="item.id"
:product="item"
/>
</view>
</template>
配置说明: 项目使用阿里云OSS进行文件存储,相关配置位于config.js中:
使用示例:
// 在组件中使用
import { uploadFile } from '@/utils/oss-upload'
export default {
methods: {
async onUpload(file) {
try {
const result = await uploadFile(file)
console.log('上传成功:', result.url)
} catch (error) {
console.error('上传失败:', error)
}
}
}
}
// 在组件中使用
import { uploadFiles } from '@/utils/oss-upload'
export default {
methods: {
async onUploadMultiple(files) {
try {
const results = await uploadFiles(files)
results.forEach(result => {
console.log('文件上传成功:', result.url)
})
} catch (error) {
console.error('上传失败:', error)
}
}
}
}
<template>
<uv-upload
:fileList="fileList"
@afterRead="afterRead"
@delete="deletePic"
name="1"
multiple
:maxCount="maxCount"
></uv-upload>
</template>
<script>
import { uploadFile } from '@/utils/oss-upload'
export default {
data() {
return {
fileList: [],
maxCount: 9
}
},
methods: {
// 新增图片
async afterRead(event) {
let lists = [].concat(event.file)
let fileListLen = this.fileList.length
lists.map((item) => {
this.fileList.push({
...item,
status: 'uploading',
message: '上传中'
})
})
for (let i = 0; i < lists.length; i++) {
const result = await uploadFile(lists[i])
let item = this.fileList[fileListLen + i]
this.fileList.splice(fileListLen + i, 1, Object.assign(item, {
status: 'success',
message: '',
url: result
}))
}
},
// 删除图片
deletePic(event) {
this.fileList.splice(event.index, 1)
}
}
}
</script>
注意事项:
// pages/product/list.vue
import listMixin from '@/mixins/list.js'
export default {
mixins: [listMixin],
data() {
return {
mixinsListApi: 'product.list',
}
},
methods: {
// 分类切换
onCategoryChange(categoryId) {
this.queryParams.categoryId = categoryId
this.getData()
}
}
}
// pages/product/detail.vue
import configMixin from '@/mixins/configList.js'
export default {
mixins: [configMixin],
data() {
return {
productId: '',
detail: {}
}
},
onLoad(options) {
this.productId = options.id
this.getDetail()
},
methods: {
getDetail() {
this.$api('product.detail', {
id: this.productId
}, res => {
this.detail = res.result
// 设置分享信息
this.Gshare.title = this.detail.name
this.Gshare.path = `/pages/product/detail?id=${this.productId}`
})
}
}
}