Vue3.0小兔鲜儿电商项目
基于 vue3.0 的组合 AP I方式与选项 API 的方式开发的一个综合品类的电商前台系统。 实现了一套完整的电商业务流程,从首页,类目,搜索,品牌,商品详情,购物车,结算,支付,个人中心,订单管理,收货地址管理,评价中心,和其他个人信息管理业务。
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 导入自己UI组件库
import UI from '@/components/library'
// 1. 重置样式的库
import 'normalize.css'
// 2. 自己项目的重置样式和公用样式
import '@/assets/styles/common.less'
// mockjs
import '@/mock'
createApp(App).use(store).use(router).use(UI).mount('#app')
import Mock from 'mockjs'
import qs from 'qs'
// 基本配置
Mock.setup({
// 随机延时200-300毫秒,模拟网络延时
timeout: '200-300'
})
// 拦截接口 /my/test
// 1. 接口地址路径规则,需要匹配到它
// 2. 请求方式
// 3. 返回数据(函数返回数据)
Mock.mock(/\/my\/test/, 'get', () => {
// 随机数据逻辑 目标:5条数据 [{id:'',name:''},...]
const arr = []
for (let i = 0; i < 5; i++) {
// arr.push(Mock.mock('@id'))
arr.push(Mock.mock({
id: '@id',
name: '@cname'
}))
}
return { msg: '获取数据成功', result: arr }
})
// 模拟 我的收藏
Mock.mock(/\/member\/collect/, 'get', config => {
const queryString = config.url.split('?')[1]
const queryObject = qs.parse(queryString)
const items = []
for (let i = 0; i < +queryObject.pageSize; i++) {
items.push(Mock.mock({
id: '@id',
name: '@ctitle(10,20)',
desc: '@ctitle(4,10)',
price: '@float(100,200,2,2)',
// http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_7.jpg
picture: `http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_${Mock.mock('@integer(1,8)')}.jpg`
}))
}
return {
msg: '获取收藏商品成功',
result: {
counts: 35,
pageSize: +queryObject.pageSize,
page: +queryObject.page,
items
}
}
})
/**
* Find power-set of a set using BITWISE approach.
*
* @param {*[]} originalSet
* @return {*[][]}
*/
export default function bwPowerSet(originalSet) {
const subSets = [];
// We will have 2^n possible combinations (where n is a length of original set).
// It is because for every element of original set we will decide whether to include
// it or not (2 options for each set element).
const numberOfCombinations = 2 ** originalSet.length;
// Each number in binary representation in a range from 0 to 2^n does exactly what we need:
// it shows by its bits (0 or 1) whether to include related element from the set or not.
// For example, for the set {1, 2, 3} the binary number of 0b010 would mean that we need to
// include only "2" to the current set.
for (let combinationIndex = 0; combinationIndex < numberOfCombinations; combinationIndex += 1) {
const subSet = [];
for (let setElementIndex = 0; setElementIndex < originalSet.length; setElementIndex += 1) {
// Decide whether we need to include current element into the subset or not.
if (combinationIndex & (1 << setElementIndex)) {
subSet.push(originalSet[setElementIndex]);
}
}
// Add current subset to the list of all subsets.
subSets.push(subSet);
}
return subSets;
}