Commit 104523c6 authored by Junling Bu's avatar Junling Bu
Browse files

doc

parents 70c31ee4 4ee32ff6
export default {
props: {
goods: {
type: Object,
default: () => ({})
}
},
computed: {
goodsStatusToMe() {
const is_buy = this.goods.is_buy;
const is_collect = this.goods.is_collect;
return is_buy ? '我购买过' : is_collect ? '我收藏过' : '';
}
},
methods: {
OnClick() {
this.$emit('click');
}
}
};
export default {
data() {
return {
pages: {
perPage: 8,
currPage: 1,
pageCount: 1
},
items: [],
loading: false,
finished: false,
isEmpty: false
};
},
methods: {
async resetInit() {
this.resetData();
// debugger;
const page = await this.initData();
this.$nextTick(() => {
this.setPages(page);
});
},
isFinished() {
this.finished = true;
this.loading = false;
},
async loadMore() {
console.log('loadmore');
const vm = this;
if (vm.pages.pageCount < vm.pages.currPage) {
vm.$toast({
message: '没有更多了~',
position: 'top'
});
vm.isFinished();
} else {
const page = await vm.initData(true);
vm.nextPage(page.pageCount);
}
vm.loading = false;
},
nextPage(pageCount = 1) {
this.pages.currPage += 1;
this.pages.pageCount = pageCount;
},
setPages(page = {}) {
this.isEmpty = page.totalCount === 0;
if (page.totalCount <= this.pages.perPage) {
// 不满一页
this.isFinished();
} else {
// 下一页
this.nextPage(page.pageCount);
}
},
resetData() {
this.items = [];
this.pages = {
perPage: 8,
currPage: 1,
pageCount: 1
};
this.loading = false;
this.finished = false;
this.isEmpty = false;
}
}
};
export default {
data() {
return {
pages: {
perPage: 8,
currPage: 1,
pageCount: 1
},
loading: false,
finished: false,
isEmpty: false
};
},
methods: {
async resetInit() {
this.resetData();
const page = await this.initData();
this.$nextTick(() => {
this.setPages(page);
});
},
isFinished() {
this.finished = true;
this.loading = false;
},
async loadMore() {
console.log('loadmore');
const {
pages: { pageCount, currPage }
} = this;
const finish = pageCount < currPage;
if (finish) {
this.isFinished();
} else {
this.setPages(await this.initData(true));
}
this.loading = false;
},
nextPage(pageCount = 1) {
this.pages.currPage += 1;
this.pages.pageCount = pageCount;
this.loading = false;
},
setPages(page = {}) {
this.isEmpty = page.totalCount === 0;
if (page.totalCount <= this.pages.perPage) {
// 不满一页
this.isFinished();
} else {
// 下一页
this.nextPage(page.pageCount);
}
},
resetData() {
this.pages = {
perPage: 8,
currPage: 1,
pageCount: 1
};
this.loading = true;
this.finished = false;
this.isEmpty = false;
}
}
};
// 滚动条记录, 适用于 keep-alive 组件
import { debounce } from 'lodash';
export default {
data() {
return {
scrollTop: 0
};
},
mounted() {
const vm = this;
vm.$el.addEventListener(
'scroll',
debounce(() => {
vm.scrollTop = vm.$el.scrollTop;
}, 50)
);
},
activated() {
this.$el.scrollTop = this.scrollTop;
}
};
import axios from 'axios';
import _ from 'lodash';
import qs from 'qs';
import { Dialog, Toast } from 'vant';
import Vue from 'vue';
Vue.use(Toast);
const instance = axios.create({
timeout: 5000,
baseURL: ''
});
instance.interceptors.request.use(
config => {
if (!config.headers['X-Litemall-Token']) {
config.headers['X-Litemall-Token'] = `${window.localStorage.getItem(
'Authorization'
) || ''}`;
}
return config;
},
err => Promise.reject(err)
);
instance.interceptors.response.use(
res => {
let litemall = _.has(res.data, 'errno') && res.data.errno !== 0;
let oldmall = _.has(res.data, 'success') && !res.data.success;
if (litemall || oldmall) {
switch (res.data.code || res.data.errno) {
case 422: {
const flag = Array.isArray(res.data.data) && res.data.data.length;
Dialog.alert({
message: flag ? res.data.data[0].message : res.data.message
});
break;
}
case 401:
break;
case 404:
break;
case 740: {
Toast.fail('优惠券已经领取过');
break;
}
case 501: {
Toast.fail('请登录');
setTimeout(() => {
window.location = '#/login/'
}, 1500)
break;
}
default:
Toast.fail(res.data.errmsg)
}
return Promise.reject(res);
}
return res;
},
error => {
Dialog.alert({
title: '警告',
message: error.message
});
return Promise.reject(error);
}
);
const post = (url, data, config = {}) => instance.post(url, data, config);
const put = (url, data, config = {}) => instance.put(url, data, config);
const get = (url, params, config = {}) =>
instance.get(url, {
params,
...config
});
const deleteMethod = (url, config = {}) =>
instance({
url,
method: 'delete',
...config
});
export default {
install(Vue) {
Vue.prototype.$reqGet = get;
Vue.prototype.$reqPost = post;
Vue.prototype.$reqPut = put;
Vue.prototype.$reqDel = deleteMethod;
}
};
import VueCountdown from '@xkeshi/vue-countdown';
export default {
install(Vue) {
Vue.component('countdown', VueCountdown);
}
};
const Tabbar = () =>
import(/* webpackChunkName: "Tabbar" */ '@/vue/components/Tabbar/');
import asyncLoader from 'core/async-loader';
export default [
{
path: '/',
name: 'home',
components: {
default: asyncLoader('home/tabbar-home'),
tabbar: Tabbar
},
meta: {
keepAlive: true
}
},
{
path: '*',
redirect: {
name: 'home'
}
}
];
import Vue from 'vue';
import Router from 'vue-router';
import { getLocalStorage } from '@/core/utils/local-storage';
import home from './home';
import items from './items';
import user from './user';
import order from './order';
import login from './login';
Vue.use(Router);
const RouterModel = new Router({
routes: [...home, ...items, ...user, ...order, ...login]
});
RouterModel.beforeEach((to, from, next) => {
const { Authorization, user_id } = getLocalStorage(
'Authorization',
'user_id'
);
if (!Authorization && !user_id) {
if (to.meta.login) {
next({ name: 'login', query: { redirect: to.name } });
return;
}
}
next();
});
export default RouterModel;
import asyncLoader from 'core/async-loader';
const Tabbar = () =>
import(/* webpackChunkName: "Tabbar" */ '@/vue/components/Tabbar/');
export default [
{
path: '/items',
name: 'class',
meta: {
keepAlive: true
},
components: {
default: asyncLoader('items/tabbar-class'),
tabbar: Tabbar
}
},
{
path: '/items/search',
name: 'search',
meta: {
keepAlive: true
},
component: asyncLoader('items/search')
},
{
path: '/items/search/result',
name: 'search-result',
meta: {
keepAlive: true
},
component: asyncLoader('items/search-result'),
props: route => route.query
},
{
path: '/items/detail/:itemId',
name: 'detail',
props: true,
component: asyncLoader('items/detail')
},
{
path: '/items/list',
name: 'list',
component: asyncLoader('items/list'),
props: route => ({
itemClass: +route.query.itemClass
})
}
];
import asyncLoader from 'core/async-loader';
const login = asyncLoader('login/login');
const registerGetCode = asyncLoader('login/register-getCode');
const registerSubmit = asyncLoader('login/register-submit');
const registerStatus = asyncLoader('login/register-status');
const forget = asyncLoader('login/forget');
const forgetReset = asyncLoader('login/forget-reset');
const forgetStatus = asyncLoader('login/forget-status');
export default [
{
path: '/login',
name: 'login',
component: login
},
{
path: '/login/registerGetCode',
name: 'registerGetCode',
component: registerGetCode
},
{
path: '/login/registerSubmit',
name: 'registerSubmit',
component: registerSubmit
},
{
path: '/login/registerStatus/:status',
name: 'registerStatus',
props: true,
component: registerStatus
},
{
path: '/login/forget',
name: 'forget',
component: forget
},
{
path: '/login/forget/reset',
name: 'forgetReset',
component: forgetReset
},
{
path: '/login/forget/reset/:status',
name: 'forgetStatus',
props: true,
component: forgetStatus
}
];
import asyncLoader from 'core/async-loader';
const tab_cart = asyncLoader('order/tabbar-cart');
const PlaceOrderEntity = asyncLoader('order/place-order-entity');
const orderDetail = asyncLoader('order/orderDetail');
const PlaceOrderVirtual = asyncLoader('order/place-order-virtual');
const Payment = asyncLoader('order/payment');
const PaymentStatus = asyncLoader('order/payment-status');
const Tabbar = () =>
import(/* webpackChunkName: "Tabbar" */ '@/vue/components/Tabbar/');
export default [
{
path: '/order',
name: 'cart',
meta: {
login: true
},
components: { default: tab_cart, tabbar: Tabbar }
},
{
path: '/order/placeOrderEntity',
name: 'placeOrderEntity',
component: PlaceOrderEntity
},
{
path: '/order/orderDetail',
name: 'orderDetail',
component: orderDetail
},
{
path: '/order/placeOrderVirtual',
name: 'placeOrderVirtual',
component: PlaceOrderVirtual
},
{
path: '/order/payment',
name: 'payment',
component: Payment
},
{
path: '/order/payment/:status',
name: 'paymentStatus',
component: PaymentStatus,
props: true
}
];
import asyncLoader from 'core/async-loader';
const tab_user = asyncLoader('user/tabbar-user');
const UserCollect = asyncLoader('user/module-collect');
const UserTeam = asyncLoader('user/module-team');
const UserInvitation = asyncLoader('user/module-invitation');
const UserAddress = asyncLoader('user/module-address');
const UserAddressEdit = asyncLoader('user/module-address-edit');
const UserAutonym = asyncLoader('user/module-autonym');
const UserAutonymEdit = asyncLoader('user/module-autonym-edit');
const UserServer = asyncLoader('user/module-server');
const UserInformation = asyncLoader('user/user-information-set');
const UserInfo_SetBg = asyncLoader('user/user-information-set/set-bg');
const UserInfo_SetMobile = asyncLoader('user/user-information-set/set-mobile');
const UserInfo_SetNickname = asyncLoader(
'user/user-information-set/set-nickname'
);
const UserInfo_SetPassword = asyncLoader(
'user/user-information-set/set-password'
);
const UserOrderEntityList = asyncLoader('user/order-entity-list');
const UserOrderEleList = asyncLoader('user/order-ele-list');
const UserRefundList = asyncLoader('user/refund-list');
const Tabbar = () =>
import(/* webpackChunkName: "Tabbar" */ '@/vue/components/Tabbar/');
export default [
{
path: '/user',
name: 'user',
meta: {
keepAlive: true
},
components: { default: tab_user, tabbar: Tabbar }
},
{
path: '/user/collect',
name: 'collect',
meta: {
login: true
},
component: UserCollect
},
{
path: '/user/team',
name: 'team',
meta: {
login: true
},
component: UserTeam
},
{
path: '/user/invitation',
name: 'invitation',
meta: {
login: true
},
component: UserInvitation
},
{
path: '/user/address',
name: 'address',
meta: {
login: true
},
component: UserAddress
},
{
path: '/user/address/edit/:addressId',
name: 'address-edit',
props: true,
meta: {
login: true
},
component: UserAddressEdit
},
{
path: '/user/autonym',
name: 'autonym',
component: UserAutonym
},
{
path: '/user/autonym/edit',
name: 'autonym-edit',
component: UserAutonymEdit
},
{
path: '/user/server',
name: 'user-server',
component: UserServer
},
{
path: '/user/information',
name: 'user-information',
meta: {
login: true
},
component: UserInformation
},
{
path: '/user/information/setbg',
name: 'user-info-setbg',
component: UserInfo_SetBg
},
{
path: '/user/information/setMobile',
name: 'user-info-setMobile',
component: UserInfo_SetMobile
},
{
path: '/user/information/setNickname',
name: 'user-info-setNickname',
component: UserInfo_SetNickname
},
{
path: '/user/information/setPassword',
name: 'user-info-setPassword',
component: UserInfo_SetPassword
},
{
path: '/user/order/list/:active',
name: 'user-order-list',
props: true,
component: UserOrderEntityList
},
{
path: '/user/orderEle/list/:active',
name: 'user-order-ele-list',
props: true,
component: UserOrderEleList
},
{
path: '/user/refund/list',
name: 'user-refund-list',
component: UserRefundList
}
];
const path = require('path');
function resolve(dir = '') {
return path.join(__dirname, './src', dir);
}
module.exports = {
outputDir: 'dist',
assetsDir: 'static',
productionSourceMap: false,
devServer: {
proxy: {
'/wx': {
target: 'http://127.0.0.1:8080',
// pathRewrite: {
// '/api': ''
// }
}
},
//九键输入法的 「mall」= 「6255」
port: 6255,
},
chainWebpack: config => {
config.plugins.delete('prefetch');
config.plugins.delete('preload');
},
configureWebpack: {
resolve: {
alias: {
core: resolve('core')
}
},
optimization: {
runtimeChunk: {
name: entrypoint => `runtime~${entrypoint.name}`
},
splitChunks: {
minChunks: 2,
minSize: 20000,
maxAsyncRequests: 20,
maxInitialRequests: 30,
name: false
}
}
},
css: {
loaderOptions: {
sass: {
data:
'@import "@/assets/scss/_var.scss";@import "@/assets/scss/_mixin.scss";'
}
}
}
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment