电商应用、社交应用
本课程将通过两个完整的实战项目——电商应用和社交应用,综合运用前面所学的UniApp知识。我们将从项目架构设计到功能实现,带你完成一个完整的应用开发流程。
电商应用是一个功能完整的购物平台,包含商品展示、购物车、订单管理、用户中心等核心功能。
ecommerce-app/
├── pages/
│ ├── index/ # 首页
│ │ ├── index.vue
│ │ └── components/
│ ├── category/ # 分类页
│ ├── product/ # 商品相关
│ │ ├── list.vue # 商品列表
│ │ └── detail.vue # 商品详情
│ ├── cart/ # 购物车
│ ├── order/ # 订单相关
│ │ ├── list.vue # 订单列表
│ │ └── detail.vue # 订单详情
│ └── user/ # 用户中心
│ ├── profile.vue # 个人资料
│ └── address.vue # 地址管理
├── components/ # 公共组件
│ ├── ProductCard.vue # 商品卡片
│ ├── CartItem.vue # 购物车项
│ └── TabBar.vue # 底部导航
├── store/ # 状态管理
│ ├── index.js
│ ├── modules/
│ │ ├── cart.js # 购物车模块
│ │ ├── user.js # 用户模块
│ │ └── product.js # 商品模块
├── api/ # API接口
│ ├── index.js
│ ├── product.js
│ ├── cart.js
│ └── order.js
├── utils/ # 工具函数
│ ├── request.js # 请求封装
│ ├── storage.js # 存储工具
│ └── auth.js # 认证工具
└── static/ # 静态资源
├── images/
└── icons/
{{ category.name }}
推荐商品
更多 >
¥{{ product.price }}
{{ product.name }}
已售 {{ product.sales }} 件
{{ key }}:
{{ value }}
{{ isFavorite ? '已收藏' : '收藏' }}
购物车
{{ cartCount }}
const CART_KEY = 'shopping_cart'
export default {
namespaced: true,
state: {
cartItems: []
},
mutations: {
SET_CART_ITEMS(state, items) {
state.cartItems = items
uni.setStorageSync(CART_KEY, items)
},
ADD_TO_CART(state, item) {
const existingIndex = state.cartItems.findIndex(
i => i.productId === item.productId &&
JSON.stringify(i.specs) === JSON.stringify(item.specs)
)
if (existingIndex !== -1) {
state.cartItems[existingIndex].quantity += item.quantity
} else {
state.cartItems.push(item)
}
uni.setStorageSync(CART_KEY, state.cartItems)
},
UPDATE_QUANTITY(state, { index, quantity }) {
if (state.cartItems[index]) {
state.cartItems[index].quantity = quantity
uni.setStorageSync(CART_KEY, state.cartItems)
}
},
REMOVE_ITEM(state, index) {
state.cartItems.splice(index, 1)
uni.setStorageSync(CART_KEY, state.cartItems)
},
CLEAR_CART(state) {
state.cartItems = []
uni.removeStorageSync(CART_KEY)
},
TOGGLE_SELECT(state, index) {
if (state.cartItems[index]) {
state.cartItems[index].selected = !state.cartItems[index].selected
}
},
SELECT_ALL(state, selected) {
state.cartItems.forEach(item => {
item.selected = selected
})
}
},
actions: {
initCart({ commit }) {
const items = uni.getStorageSync(CART_KEY) || []
commit('SET_CART_ITEMS', items)
},
addToCart({ commit, dispatch }, item) {
commit('ADD_TO_CART', item)
dispatch('updateCartCount')
},
updateQuantity({ commit, dispatch }, payload) {
commit('UPDATE_QUANTITY', payload)
dispatch('updateCartCount')
},
removeItem({ commit, dispatch }, index) {
commit('REMOVE_ITEM', index)
dispatch('updateCartCount')
},
clearCart({ commit }) {
commit('CLEAR_CART')
},
toggleSelect({ commit }, index) {
commit('TOGGLE_SELECT', index)
},
selectAll({ commit }, selected) {
commit('SELECT_ALL', selected)
},
updateCartCount({ state, rootState }) {
const count = state.cartItems.reduce((sum, item) => sum + item.quantity, 0)
rootState.cartCount = count
}
},
getters: {
cartCount: state => state.cartItems.reduce((sum, item) => sum + item.quantity, 0),
selectedItems: state => state.cartItems.filter(item => item.selected),
selectedTotal: state => {
return state.cartItems
.filter(item => item.selected)
.reduce((total, item) => total + item.price * item.quantity, 0)
},
allSelected: state => {
if (state.cartItems.length === 0) return false
return state.cartItems.every(item => item.selected)
}
}
}
社交应用是一个功能完整的社交平台,包含动态发布、好友互动、消息通知、个人主页等核心功能。
取消
发布动态
发布
{{ content.length }}/500
×
{{ location || '添加位置' }}
{{ topic || '添加话题' }}
{{ visibilityText }}
{{ post.user.name }}
{{ formatTime(post.createTime) }}
•••
{{ post.content }}
{{ post.location }}
{{ post.likeCount || '赞' }}
{{ post.commentCount || '评论' }}
分享
{{ comment.user.name }}
:{{ comment.content }}
查看全部{{ post.commentCount }}条评论
加载中...
没有更多了
// 1. 构建生产版本
npm run build:mp-weixin
// 2. 上传到微信开发者工具
// 打开微信开发者工具 -> 导入项目 -> 上传
// 3. 提交审核
// 微信公众平台 -> 版本管理 -> 提交审核
// 4. 发布上线
// 审核通过后点击发布
本课程通过两个完整的实战项目,综合运用了UniApp的各项技术:
通过这两个项目的实践,你应该已经具备了独立开发复杂UniApp应用的能力。继续学习和实践,你将能够开发出更加优秀的应用!