|  | 6 months ago | |
|---|---|---|
| .trae/rules | 6 months ago | |
| api | 6 months ago | |
| components | 6 months ago | |
| mixins | 6 months ago | |
| pages | 6 months ago | |
| pages_order | 6 months ago | |
| static | 6 months ago | |
| store | 7 months ago | |
| uni_modules | 7 months ago | |
| utils | 7 months ago | |
| .gitignore | 7 months ago | |
| App.vue | 7 months ago | |
| README.en.md | 7 months ago | |
| README.md | 7 months ago | |
| common.scss | 7 months ago | |
| config.js | 7 months ago | |
| index.html | 7 months ago | |
| main.js | 7 months ago | |
| manifest.json | 7 months ago | |
| package.json | 7 months ago | |
| pages.json | 6 months ago | |
| uni.css | 6 months ago | |
| uni.min.css | 6 months ago | |
| uni.promisify.adaptor.js | 7 months ago | |
| uni.scss | 6 months 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'  // 设置默认单位
  },
})
// UI文档地址 https://www.uvui.cn/
提供列表数据的加载、分页、下拉刷新、上拉加载更多等功能。
主要功能:
使用示例:
// 在页面中使用list混入
import listMixin from '@/mixins/list.js'
export default {
  mixins: [listMixin],
  data() {
    return {
      // 指定API接口
      mixinsListApi: 'productList'
    }
  }
}
已全局引入的配置管理混入,无需手动引入即可使用。
主要功能:
配置参数:
// 分享配置示例
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())
// 项目中在Vue集成了dayjs >>,可以直接使用
// 在utils/index中Vue.prototype.$dayjs
this.$dayjs()
// 微信网页支付调用
import { wxPay } from '@/utils/pay'
wxPay(orderData)
使用示例:
<template>
  <view>
    <navbar title="商品列表" />
  </view>
</template>
配置说明: 项目使用阿里云OSS进行文件存储,相关配置位于config.js中:
使用示例:
export default {
  methods: {
    onUpload(file) {
		this.$Oss.ossUpload(file.path).then(url => {
			this.filePath = url
		})
    }
  }
}
<template>
  <uv-upload
    :fileList="fileList"
    @afterRead="afterRead"
    @delete="deleteImage"
    name="1"
    multiple
    :maxCount="maxCount"
  ></uv-upload>
</template>
<script>
export default {
  data() {
    return {
      fileList: [],
      maxCount: 9
    }
  },
  methods: {
    // 新增图片
    afterRead(e) {
		e.file.forEach(file => {
			this.$Oss.ossUpload(file.url).then(url => {
				this.fileList.push({
					url
				})
			})
		})
	},
    // 删除图片
    deleteImage(e) {
		this.fileList.splice(e.index, 1)
	},
  }
}
</script>
注意事项:
// pages/product/list.vue
import listMixin from '@/mixins/list.js'
export default {
  mixins: [listMixin],
  data() {
    return {
      mixinsListApi: 'productList',
    }
  },
  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('productDetail', {
        id: this.productId
      }, res => {
        this.detail = res.result
        // 设置分享信息
        this.Gshare.title = this.detail.name
        this.Gshare.path = `/pages/product/detail?id=${this.productId}`
      })
    }
  }
}