├── goods
├── static
│ ├── .gitkeep
│ ├── images
│ │ ├── 1.jpg
│ │ ├── 10.jpg
│ │ ├── 11.jpg
│ │ ├── 12.jpg
│ │ ├── 13.jpg
│ │ ├── 14.jpg
│ │ ├── 15.jpg
│ │ ├── 16.jpg
│ │ ├── 2.jpg
│ │ ├── 3.jpg
│ │ ├── 4.jpg
│ │ ├── 5.jpg
│ │ ├── 6.jpg
│ │ ├── 7.jpg
│ │ ├── 8.jpg
│ │ ├── 9.jpg
│ │ ├── mi6.jpg
│ │ ├── note.jpg
│ │ ├── imooc.jpg
│ │ ├── loading.gif
│ │ ├── photo.jpg
│ │ ├── zipai.jpg
│ │ ├── no-image.png
│ │ ├── pingheng.jpg
│ │ ├── icon-loading.png
│ │ └── icon-add-plus.png
│ └── reset.css
├── .eslintignore
├── config
│ ├── prod.env.js
│ ├── dev.env.js
│ └── index.js
├── server
│ ├── views
│ │ ├── index.jade
│ │ ├── error.jade
│ │ └── layout.jade
│ ├── public
│ │ ├── stylesheets
│ │ │ └── style.css
│ │ └── javascripts
│ │ │ └── common.js
│ ├── routes
│ │ ├── index.js
│ │ ├── goods.js
│ │ └── users.js
│ ├── models
│ │ ├── goods.js
│ │ └── users.js
│ ├── bin
│ │ └── www
│ └── app.js
├── src
│ ├── base
│ │ ├── modal
│ │ │ ├── icon-close.png
│ │ │ └── modal.vue
│ │ ├── goods-list
│ │ │ ├── icon-delete.png
│ │ │ ├── icon-selected.png
│ │ │ ├── icon-delete-active.png
│ │ │ └── goods-list.vue
│ │ ├── crumbs
│ │ │ └── crumbs.vue
│ │ ├── cart-control
│ │ │ └── cart-control.vue
│ │ └── confirm
│ │ │ └── confirm.vue
│ ├── components
│ │ ├── header
│ │ │ ├── logo.png
│ │ │ ├── icon-lock.png
│ │ │ ├── icon-person.png
│ │ │ ├── icon-shopcar.png
│ │ │ └── header.vue
│ │ ├── goods
│ │ │ ├── icon-check.png
│ │ │ ├── icon-arrow-top.png
│ │ │ ├── icon-arrow-top-active.png
│ │ │ └── goods.vue
│ │ ├── cart
│ │ │ ├── icon-selected.png
│ │ │ └── cart.vue
│ │ ├── order-success
│ │ │ ├── icon-success.png
│ │ │ └── order-success.vue
│ │ ├── select-address
│ │ │ ├── icon-arrow.png
│ │ │ ├── icon-delete.png
│ │ │ ├── icon-add-plus.png
│ │ │ ├── icon-arrow-active.png
│ │ │ ├── icon-delete-active.png
│ │ │ └── select-address.vue
│ │ ├── footer
│ │ │ └── footer.vue
│ │ ├── address
│ │ │ └── address.vue
│ │ └── preview-order
│ │ │ └── preview-order.vue
│ ├── store
│ │ ├── actions.js
│ │ ├── mutation-types.js
│ │ ├── state.js
│ │ ├── index.js
│ │ ├── getters.js
│ │ └── mutations.js
│ ├── App.vue
│ ├── common
│ │ ├── js
│ │ │ └── format.js
│ │ └── style
│ │ │ └── basic.less
│ ├── main.js
│ └── router
│ │ └── index.js
├── .editorconfig
├── .gitignore
├── .postcssrc.js
├── build
│ ├── dev-client.js
│ ├── vue-loader.conf.js
│ ├── build.js
│ ├── webpack.dev.conf.js
│ ├── check-versions.js
│ ├── webpack.base.conf.js
│ ├── utils.js
│ ├── dev-server.js
│ └── webpack.prod.conf.js
├── .babelrc
├── index.html
├── README.md
├── .eslintrc.js
├── demo
│ ├── ES6.html
│ ├── vue-resource.html
│ └── axios.html
├── mock
│ └── goods.json
└── package.json
└── README.md
/goods/static/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/goods/.eslintignore:
--------------------------------------------------------------------------------
1 | build/*.js
2 | config/*.js
3 |
--------------------------------------------------------------------------------
/goods/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/goods/static/images/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/1.jpg
--------------------------------------------------------------------------------
/goods/static/images/10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/10.jpg
--------------------------------------------------------------------------------
/goods/static/images/11.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/11.jpg
--------------------------------------------------------------------------------
/goods/static/images/12.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/12.jpg
--------------------------------------------------------------------------------
/goods/static/images/13.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/13.jpg
--------------------------------------------------------------------------------
/goods/static/images/14.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/14.jpg
--------------------------------------------------------------------------------
/goods/static/images/15.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/15.jpg
--------------------------------------------------------------------------------
/goods/static/images/16.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/16.jpg
--------------------------------------------------------------------------------
/goods/static/images/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/2.jpg
--------------------------------------------------------------------------------
/goods/static/images/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/3.jpg
--------------------------------------------------------------------------------
/goods/static/images/4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/4.jpg
--------------------------------------------------------------------------------
/goods/static/images/5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/5.jpg
--------------------------------------------------------------------------------
/goods/static/images/6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/6.jpg
--------------------------------------------------------------------------------
/goods/static/images/7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/7.jpg
--------------------------------------------------------------------------------
/goods/static/images/8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/8.jpg
--------------------------------------------------------------------------------
/goods/static/images/9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/9.jpg
--------------------------------------------------------------------------------
/goods/static/images/mi6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/mi6.jpg
--------------------------------------------------------------------------------
/goods/static/images/note.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/note.jpg
--------------------------------------------------------------------------------
/goods/static/images/imooc.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/imooc.jpg
--------------------------------------------------------------------------------
/goods/static/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/loading.gif
--------------------------------------------------------------------------------
/goods/static/images/photo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/photo.jpg
--------------------------------------------------------------------------------
/goods/static/images/zipai.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/zipai.jpg
--------------------------------------------------------------------------------
/goods/server/views/index.jade:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1= title
5 | p Welcome to #{title}
6 |
--------------------------------------------------------------------------------
/goods/static/images/no-image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/no-image.png
--------------------------------------------------------------------------------
/goods/static/images/pingheng.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/pingheng.jpg
--------------------------------------------------------------------------------
/goods/src/base/modal/icon-close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/base/modal/icon-close.png
--------------------------------------------------------------------------------
/goods/src/components/header/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/header/logo.png
--------------------------------------------------------------------------------
/goods/static/images/icon-loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/icon-loading.png
--------------------------------------------------------------------------------
/goods/static/images/icon-add-plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/static/images/icon-add-plus.png
--------------------------------------------------------------------------------
/goods/src/base/goods-list/icon-delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/base/goods-list/icon-delete.png
--------------------------------------------------------------------------------
/goods/src/components/goods/icon-check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/goods/icon-check.png
--------------------------------------------------------------------------------
/goods/src/components/header/icon-lock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/header/icon-lock.png
--------------------------------------------------------------------------------
/goods/server/views/error.jade:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1= message
5 | h2= error.status
6 | pre #{error.stack}
7 |
--------------------------------------------------------------------------------
/goods/src/base/goods-list/icon-selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/base/goods-list/icon-selected.png
--------------------------------------------------------------------------------
/goods/src/components/cart/icon-selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/cart/icon-selected.png
--------------------------------------------------------------------------------
/goods/src/components/header/icon-person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/header/icon-person.png
--------------------------------------------------------------------------------
/goods/src/components/goods/icon-arrow-top.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/goods/icon-arrow-top.png
--------------------------------------------------------------------------------
/goods/src/components/header/icon-shopcar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/header/icon-shopcar.png
--------------------------------------------------------------------------------
/goods/src/base/goods-list/icon-delete-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/base/goods-list/icon-delete-active.png
--------------------------------------------------------------------------------
/goods/src/components/order-success/icon-success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/order-success/icon-success.png
--------------------------------------------------------------------------------
/goods/src/components/select-address/icon-arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/select-address/icon-arrow.png
--------------------------------------------------------------------------------
/goods/src/components/select-address/icon-delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/select-address/icon-delete.png
--------------------------------------------------------------------------------
/goods/src/components/goods/icon-arrow-top-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/goods/icon-arrow-top-active.png
--------------------------------------------------------------------------------
/goods/src/components/select-address/icon-add-plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/select-address/icon-add-plus.png
--------------------------------------------------------------------------------
/goods/src/components/select-address/icon-arrow-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/select-address/icon-arrow-active.png
--------------------------------------------------------------------------------
/goods/src/components/select-address/icon-delete-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/willemwei/goods/HEAD/goods/src/components/select-address/icon-delete-active.png
--------------------------------------------------------------------------------
/goods/server/views/layout.jade:
--------------------------------------------------------------------------------
1 | doctype html
2 | html
3 | head
4 | title= title
5 | link(rel='stylesheet', href='/stylesheets/style.css')
6 | body
7 | block content
8 |
--------------------------------------------------------------------------------
/goods/server/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 50px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 |
6 | a {
7 | color: #00B7FF;
8 | }
9 |
--------------------------------------------------------------------------------
/goods/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/goods/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/goods/server/public/javascripts/common.js:
--------------------------------------------------------------------------------
1 | let resInfo = (res, status, msg, result) => {
2 | res.json({
3 | status,
4 | msg,
5 | result
6 | });
7 | };
8 |
9 | module.exports.resInfo = resInfo;
10 |
--------------------------------------------------------------------------------
/goods/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Editor directories and files
9 | .idea
10 | .vscode
11 | *.suo
12 | *.ntvs*
13 | *.njsproj
14 | *.sln
15 |
--------------------------------------------------------------------------------
/goods/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | // to edit target browsers: use "browserslist" field in package.json
6 | "autoprefixer": {}
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/goods/server/routes/index.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var router = express.Router();
3 |
4 | /* GET home page. */
5 | router.get('/', function (req, res, next) {
6 | res.render('index', {title: 'Express'});
7 | });
8 |
9 | module.exports = router;
10 |
--------------------------------------------------------------------------------
/goods/src/store/actions.js:
--------------------------------------------------------------------------------
1 | import * as types from './mutation-types';
2 |
3 | export let spliceCartList = ({state, commit}, {index}) => {
4 | let cartList = state.cartList.slice();
5 | cartList.splice(index, 1);
6 |
7 | commit(types.SET_CART_LIST, cartList);
8 | };
9 |
--------------------------------------------------------------------------------
/goods/build/dev-client.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 | 'use strict'
3 | require('eventsource-polyfill')
4 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
5 |
6 | hotClient.subscribe(function (event) {
7 | if (event.action === 'reload') {
8 | window.location.reload()
9 | }
10 | })
11 |
--------------------------------------------------------------------------------
/goods/src/store/mutation-types.js:
--------------------------------------------------------------------------------
1 | export const SET_USER = 'SET_USER';
2 | export const SET_CART_LIST = 'SET_CART_LIST';
3 | export const SET_ORDER_PROCESS = 'SET_ORDER_PROCESS';
4 | export const SET_ADDRESS_LIST = 'SET_ADDRESS_LIST';
5 | export const SET_ALERT = 'SET_ALERT';
6 | export const SET_ORDER_PREVIEW = 'SET_ORDER_PREVIEW';
7 |
--------------------------------------------------------------------------------
/goods/src/store/state.js:
--------------------------------------------------------------------------------
1 | const state = {
2 | user: {},
3 | cartList: [],
4 | addressList: [],
5 | orderProcess: 0,
6 | alert: {
7 | show: false,
8 | msg: '你当前未登录!'
9 | },
10 | orderPreview: {
11 | orderTotal: 0,
12 | addressInfo: {},
13 | goodsList: []
14 | }
15 | };
16 |
17 | export default state;
18 |
--------------------------------------------------------------------------------
/goods/server/models/goods.js:
--------------------------------------------------------------------------------
1 | const mongoose = require('mongoose');
2 | const Schema = mongoose.Schema;
3 |
4 | let productSchema = new Schema({
5 | 'productId': {type: String},
6 | 'productName': {type: String},
7 | 'salePrice': {type: Number},
8 | 'productImage': {type: String}
9 | });
10 |
11 | module.exports = mongoose.model('Good', productSchema, 'goods'); // 自动加s进行关联
12 |
--------------------------------------------------------------------------------
/goods/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", {
4 | "modules": false,
5 | "targets": {
6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7 | }
8 | }],
9 | "stage-2"
10 | ],
11 | "plugins": ["transform-runtime"],
12 | "env": {
13 | "test": {
14 | "presets": ["env", "stage-2"],
15 | "plugins": ["istanbul"]
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/goods/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | goods
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/goods/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import Vuex from 'vuex';
3 | import state from './state';
4 | import * as getters from './getters';
5 | import * as actions from './actions';
6 | import mutations from './mutations';
7 | import createLog from 'vuex/dist/logger';
8 |
9 | Vue.use(Vuex);
10 |
11 | export default new Vuex.Store({
12 | state,
13 | getters,
14 | mutations,
15 | actions,
16 | plugins: [createLog()]
17 | });
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # goods-简易商城
2 | 基于Vue全家桶实现的简易商城webapp
3 |
4 | ## 演示地址:
5 | www.weish.xin:8080
6 |
7 | ## 相关技术
8 | * **vue-cli:** 搭建基础开发环境;
9 | * **vue-router:** 前端页面路由控制;
10 | * **axios:** 前后端交互;
11 | * **express:** 编写数据接口;
12 | * **mongodb:** 数据库;
13 | * **less:** css预编译工具;
14 | * **es6:** 箭头函数、Object事件等;
15 |
16 | ##
17 | 基于vue全家桶实现的简易商城,响应式页面,实现了用户登录、商品的浏览、筛选,对购物车进行编辑,提交订单,编辑地址,预览订单等相关功能。
18 | vue、vuex、vue-router、less、es6等开发前端页面,express、mongodb开发数据接口,axios实现前后端通信。
19 | 对后端数据接口的编写有了个大致的了解,对前后端分离认识加深。
20 |
--------------------------------------------------------------------------------
/goods/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
20 |
21 |
23 |
--------------------------------------------------------------------------------
/goods/src/store/getters.js:
--------------------------------------------------------------------------------
1 | export const user = (state) => {
2 | return state.user;
3 | };
4 |
5 | export const cartList = (state) => {
6 | return state.cartList;
7 | };
8 |
9 | export const orderProcess = (state) => {
10 | return state.orderProcess;
11 | };
12 |
13 | export const addressList = (state) => {
14 | return state.addressList;
15 | };
16 |
17 | export const alert = (state) => {
18 | return state.alert;
19 | };
20 |
21 | export const orderPreview = (state) => {
22 | return state.orderPreview;
23 | };
24 |
--------------------------------------------------------------------------------
/goods/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 |
6 | module.exports = {
7 | loaders: utils.cssLoaders({
8 | sourceMap: isProduction
9 | ? config.build.productionSourceMap
10 | : config.dev.cssSourceMap,
11 | extract: isProduction
12 | }),
13 | transformToRequire: {
14 | video: 'src',
15 | source: 'src',
16 | img: 'src',
17 | image: 'xlink:href'
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/goods/src/common/js/format.js:
--------------------------------------------------------------------------------
1 | export const formatMoney = (num) => {
2 | if (typeof num !== 'number') {
3 | throw new Error('传入的值非数字类型');
4 | }
5 |
6 | let sign = 1;
7 | let result = ['0', '0', '.'];
8 | let len;
9 |
10 | num = num.toFixed(2).split('');
11 | len = num.length - 3;
12 |
13 | for (let i = len - 1; i >= 0; i--) {
14 | result.push(num[i]);
15 | if (sign % 3 === 0 && sign < len) {
16 | result.push(',');
17 | }
18 | sign++;
19 | }
20 |
21 | return result.reverse().join('');
22 | };
23 |
--------------------------------------------------------------------------------
/goods/README.md:
--------------------------------------------------------------------------------
1 | # goods
2 |
3 | > vue & node & mongodb
4 |
5 | ## Build Setup
6 |
7 | ``` bash
8 | # install dependencies
9 | npm install
10 |
11 | # serve with hot reload at localhost:8080
12 | npm run dev
13 |
14 | # build for production with minification
15 | npm run build
16 |
17 | # build for production and view the bundle analyzer report
18 | npm run build --report
19 | ```
20 |
21 | For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
22 |
--------------------------------------------------------------------------------
/goods/src/common/style/basic.less:
--------------------------------------------------------------------------------
1 | .w1260 {
2 | margin: 0 auto;
3 | width: 100%;
4 | max-width: 1260px;
5 | }
6 |
7 | .no-wrap {
8 | overflow: hidden;
9 | text-overflow: ellipsis;
10 | white-space: nowrap;
11 | }
12 |
13 | .btn() {
14 | display: inline-block;
15 | margin: 0 2.5%;
16 | border: 1px solid #d1434a;
17 | width: 45%;
18 | min-width: 80px;
19 | height: 40px;
20 | font-size: 14px;
21 | font-weight: 700;
22 | text-align: center;
23 | line-height: 40px;
24 | letter-spacing: .25em;
25 | color: #d1434a;
26 | box-sizing: border-box;
27 | transition: all .3s;
28 | }
29 |
--------------------------------------------------------------------------------
/goods/src/main.js:
--------------------------------------------------------------------------------
1 | // The Vue build version to load with the `import` command
2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3 | import Vue from 'vue';
4 | import App from './App';
5 | import router from './router';
6 | import LazyLoad from 'vue-lazyload';
7 | import infiniteScroll from 'vue-infinite-scroll';
8 | import store from '@/store/index';
9 |
10 | Vue.config.productionTip = false;
11 |
12 | Vue.use(LazyLoad, {
13 | loading: '/static/images/loading.gif',
14 | error: '/static/images/no-image.png'
15 | });
16 |
17 | Vue.use(infiniteScroll);
18 |
19 | /* eslint-disable no-new */
20 | new Vue({
21 | el: '#app',
22 | router,
23 | store,
24 | template: '',
25 | components: {App}
26 | });
27 |
--------------------------------------------------------------------------------
/goods/server/models/users.js:
--------------------------------------------------------------------------------
1 | const Mongoose = require('mongoose');
2 | const Schema = Mongoose.Schema;
3 |
4 | let userSchema = new Schema({
5 | userId: String,
6 | userName: String,
7 | userPwd: String,
8 | orderList: Array,
9 | cartList: [
10 | {
11 | productId: String,
12 | productName: String,
13 | salePrice: String,
14 | productImage: String,
15 | checked: Number,
16 | productNum: Number
17 | }
18 | ],
19 | addressList: [
20 | {
21 | addressId: String,
22 | userName: String,
23 | streetName: String,
24 | postCode: Number,
25 | tel: String,
26 | isDefault: Boolean
27 | }
28 | ]
29 | });
30 |
31 | module.exports = Mongoose.model('User', userSchema, 'users');
32 |
--------------------------------------------------------------------------------
/goods/src/components/footer/footer.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
33 |
--------------------------------------------------------------------------------
/goods/src/store/mutations.js:
--------------------------------------------------------------------------------
1 | import * as types from './mutation-types';
2 |
3 | const mutations = {
4 | [types.SET_USER] (state, user) {
5 | state.user = user;
6 | },
7 | [types.SET_CART_LIST] (state, cartList) {
8 | state.cartList = cartList;
9 | },
10 | [types.SET_ORDER_PROCESS] (state, orderProcess) {
11 | state.orderProcess = orderProcess;
12 | },
13 | [types.SET_ADDRESS_LIST] (state, addressList) {
14 | state.addressList = addressList;
15 | },
16 | [types.SET_ALERT] (state, alert) {
17 | state.alert = alert;
18 | },
19 | [types.SET_ORDER_PREVIEW] (state, {totalPrice = 0, addressInfo = {}, goodsList = []}) {
20 | state.orderPreview = {
21 | totalPrice: totalPrice,
22 | addressInfo,
23 | goodsList
24 | };
25 | }
26 | };
27 |
28 | export default mutations;
29 |
--------------------------------------------------------------------------------
/goods/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parser: 'babel-eslint',
6 | parserOptions: {
7 | sourceType: 'module'
8 | },
9 | env: {
10 | browser: true,
11 | },
12 | // https://github.com/standard/standard/blob/master/docs/RULES-en.md
13 | extends: 'standard',
14 | // required to lint *.vue files
15 | plugins: [
16 | 'html'
17 | ],
18 | // add your custom rules here
19 | 'rules': {
20 | // allow paren-style arrow functions
21 | 'arrow-parens': 0,
22 | // allow async-await
23 | 'generator-star-spacing': 0,
24 | // allow debugger during development
25 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
26 | 'semi': ['error', 'always'],
27 | 'space-before-function-paren': 0,
28 | 'no-unused-vars': 0
29 | }
30 | };
31 |
--------------------------------------------------------------------------------
/goods/src/base/crumbs/crumbs.vue:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
48 |
--------------------------------------------------------------------------------
/goods/demo/ES6.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ES6 demo
6 |
7 |
8 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/goods/src/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import Router from 'vue-router';
3 | import Goods from '@/components/goods/goods';
4 | import Cart from '@/components/cart/cart';
5 | import Address from '@/components/address/address';
6 | import SelectAddress from '@/components/select-address/select-address';
7 | import PreviewOrder from '@/components/preview-order/preview-order';
8 | import OrderSuccess from '@/components/order-success/order-success';
9 |
10 | Vue.use(Router);
11 |
12 | export default new Router({
13 | mode: 'history', // history hash
14 | routes: [
15 | {
16 | path: '/',
17 | component: Goods
18 | },
19 | {
20 | path: '/goods',
21 | component: Goods
22 | },
23 | {
24 | path: '/cart',
25 | component: Cart
26 | },
27 | {
28 | path: '/address',
29 | component: Address,
30 | children: [
31 | {
32 | path: '',
33 | component: SelectAddress
34 | },
35 | {
36 | path: 'preview',
37 | component: PreviewOrder
38 | },
39 | {
40 | path: 'success',
41 | component: OrderSuccess
42 | }
43 | ]
44 | }
45 | ]
46 | });
47 |
--------------------------------------------------------------------------------
/goods/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, function (err, stats) {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false,
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/goods/build/webpack.dev.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const webpack = require('webpack')
4 | const config = require('../config')
5 | const merge = require('webpack-merge')
6 | const baseWebpackConfig = require('./webpack.base.conf')
7 | const HtmlWebpackPlugin = require('html-webpack-plugin')
8 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
9 |
10 | // add hot-reload related code to entry chunks
11 | Object.keys(baseWebpackConfig.entry).forEach(function (name) {
12 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
13 | })
14 |
15 | module.exports = merge(baseWebpackConfig, {
16 | module: {
17 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
18 | },
19 | // cheap-module-eval-source-map is faster for development
20 | devtool: '#cheap-module-eval-source-map',
21 | plugins: [
22 | new webpack.DefinePlugin({
23 | 'process.env': config.dev.env
24 | }),
25 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
26 | new webpack.HotModuleReplacementPlugin(),
27 | new webpack.NoEmitOnErrorsPlugin(),
28 | // https://github.com/ampedandwired/html-webpack-plugin
29 | new HtmlWebpackPlugin({
30 | filename: 'index.html',
31 | template: 'index.html',
32 | inject: true
33 | }),
34 | new FriendlyErrorsPlugin()
35 | ]
36 | })
37 |
--------------------------------------------------------------------------------
/goods/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 | function exec (cmd) {
7 | return require('child_process').execSync(cmd).toString().trim()
8 | }
9 |
10 | const versionRequirements = [
11 | {
12 | name: 'node',
13 | currentVersion: semver.clean(process.version),
14 | versionRequirement: packageConfig.engines.node
15 | }
16 | ]
17 |
18 | if (shell.which('npm')) {
19 | versionRequirements.push({
20 | name: 'npm',
21 | currentVersion: exec('npm --version'),
22 | versionRequirement: packageConfig.engines.npm
23 | })
24 | }
25 |
26 | module.exports = function () {
27 | const warnings = []
28 | for (let i = 0; i < versionRequirements.length; i++) {
29 | const mod = versionRequirements[i]
30 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
31 | warnings.push(mod.name + ': ' +
32 | chalk.red(mod.currentVersion) + ' should be ' +
33 | chalk.green(mod.versionRequirement)
34 | )
35 | }
36 | }
37 |
38 | if (warnings.length) {
39 | console.log('')
40 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
41 | console.log()
42 | for (let i = 0; i < warnings.length; i++) {
43 | const warning = warnings[i]
44 | console.log(' ' + warning)
45 | }
46 | console.log()
47 | process.exit(1)
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/goods/src/base/cart-control/cart-control.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
-
4 |
{{ goods.productNum ? goods.productNum : 1 }}
5 |
+
6 |
7 |
8 |
9 |
42 |
43 |
67 |
--------------------------------------------------------------------------------
/goods/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | // Template version: 1.1.3
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path');
6 | const proxyUrl = 'http://localhost:3000';
7 |
8 | module.exports = {
9 | build: {
10 | env: require('./prod.env'),
11 | index: path.resolve(__dirname, '../dist/index.html'),
12 | assetsRoot: path.resolve(__dirname, '../dist'),
13 | assetsSubDirectory: 'static',
14 | assetsPublicPath: '/',
15 | productionSourceMap: true,
16 | // Gzip off by default as many popular static hosts such as
17 | // Surge or Netlify already gzip all static assets for you.
18 | // Before setting to `true`, make sure to:
19 | // npm install --save-dev compression-webpack-plugin
20 | productionGzip: false,
21 | productionGzipExtensions: ['js', 'css'],
22 | // Run the build command with an extra argument to
23 | // View the bundle analyzer report after build finishes:
24 | // `npm run build --report`
25 | // Set to `true` or `false` to always turn it on or off
26 | bundleAnalyzerReport: process.env.npm_config_report
27 | },
28 | dev: {
29 | env: require('./dev.env'),
30 | port: process.env.PORT || 8888,
31 | autoOpenBrowser: true,
32 | assetsSubDirectory: 'static',
33 | assetsPublicPath: '/',
34 | proxyTable: {
35 | '/apis/*': {
36 | target: proxyUrl
37 | },
38 | '/apis/*/*': {
39 | target: proxyUrl
40 | },
41 | },
42 | // CSS Sourcemaps off by default because relative paths are "buggy"
43 | // with this option, according to the CSS-Loader README
44 | // (https://github.com/webpack/css-loader#sourcemaps)
45 | // In our experience, they generally work as expected,
46 | // just be aware of this issue when enabling this option.
47 | cssSourceMap: false
48 | }
49 | };
50 |
--------------------------------------------------------------------------------
/goods/server/bin/www:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /**
4 | * Module dependencies.
5 | */
6 |
7 | var app = require('../app');
8 | var debug = require('debug')('server:server');
9 | var http = require('http');
10 |
11 | /**
12 | * Get port from environment and store in Express.
13 | */
14 |
15 | var port = normalizePort(process.env.PORT || '3000');
16 | app.set('port', port);
17 |
18 | /**
19 | * Create HTTP server.
20 | */
21 |
22 | var server = http.createServer(app);
23 |
24 | /**
25 | * Listen on provided port, on all network interfaces.
26 | */
27 |
28 | server.listen(port);
29 | server.on('error', onError);
30 | server.on('listening', onListening);
31 |
32 | /**
33 | * Normalize a port into a number, string, or false.
34 | */
35 |
36 | function normalizePort(val) {
37 | var port = parseInt(val, 10);
38 |
39 | if (isNaN(port)) {
40 | // named pipe
41 | return val;
42 | }
43 |
44 | if (port >= 0) {
45 | // port number
46 | return port;
47 | }
48 |
49 | return false;
50 | }
51 |
52 | /**
53 | * Event listener for HTTP server "error" event.
54 | */
55 |
56 | function onError(error) {
57 | if (error.syscall !== 'listen') {
58 | throw error;
59 | }
60 |
61 | var bind = typeof port === 'string'
62 | ? 'Pipe ' + port
63 | : 'Port ' + port;
64 |
65 | // handle specific listen errors with friendly messages
66 | switch (error.code) {
67 | case 'EACCES':
68 | console.error(bind + ' requires elevated privileges');
69 | process.exit(1);
70 | break;
71 | case 'EADDRINUSE':
72 | console.error(bind + ' is already in use');
73 | process.exit(1);
74 | break;
75 | default:
76 | throw error;
77 | }
78 | }
79 |
80 | /**
81 | * Event listener for HTTP server "listening" event.
82 | */
83 |
84 | function onListening() {
85 | var addr = server.address();
86 | var bind = typeof addr === 'string'
87 | ? 'pipe ' + addr
88 | : 'port ' + addr.port;
89 | debug('Listening on ' + bind);
90 | }
91 |
--------------------------------------------------------------------------------
/goods/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const utils = require('./utils')
4 | const config = require('../config')
5 | const vueLoaderConfig = require('./vue-loader.conf')
6 |
7 | function resolve (dir) {
8 | return path.join(__dirname, '..', dir)
9 | }
10 |
11 | module.exports = {
12 | entry: {
13 | app: './src/main.js'
14 | },
15 | output: {
16 | path: config.build.assetsRoot,
17 | filename: '[name].js',
18 | publicPath: process.env.NODE_ENV === 'production'
19 | ? config.build.assetsPublicPath
20 | : config.dev.assetsPublicPath
21 | },
22 | resolve: {
23 | extensions: ['.js', '.vue', '.json'],
24 | alias: {
25 | 'vue$': 'vue/dist/vue.esm.js',
26 | '@': resolve('src'),
27 | }
28 | },
29 | module: {
30 | rules: [
31 | {
32 | test: /\.(js|vue)$/,
33 | loader: 'eslint-loader',
34 | enforce: 'pre',
35 | include: [resolve('src'), resolve('test')],
36 | options: {
37 | formatter: require('eslint-friendly-formatter')
38 | }
39 | },
40 | {
41 | test: /\.vue$/,
42 | loader: 'vue-loader',
43 | options: vueLoaderConfig
44 | },
45 | {
46 | test: /\.js$/,
47 | loader: 'babel-loader',
48 | include: [resolve('src'), resolve('test')]
49 | },
50 | {
51 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
52 | loader: 'url-loader',
53 | options: {
54 | limit: 10000,
55 | name: utils.assetsPath('img/[name].[hash:7].[ext]')
56 | }
57 | },
58 | {
59 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
60 | loader: 'url-loader',
61 | options: {
62 | limit: 10000,
63 | name: utils.assetsPath('media/[name].[hash:7].[ext]')
64 | }
65 | },
66 | {
67 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
68 | loader: 'url-loader',
69 | options: {
70 | limit: 10000,
71 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
72 | }
73 | }
74 | ]
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/goods/server/app.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var path = require('path');
3 | var favicon = require('serve-favicon');
4 | var logger = require('morgan');
5 | var cookieParser = require('cookie-parser');
6 | var bodyParser = require('body-parser');
7 |
8 | var index = require('./routes/index');
9 | var users = require('./routes/users');
10 | var goods = require('./routes/goods');
11 |
12 | var app = express();
13 |
14 | // view engine setup
15 | app.set('views', path.join(__dirname, 'views'));
16 | app.set('view engine', 'jade');
17 |
18 | // uncomment after placing your favicon in /public
19 | //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
20 | app.use(logger('dev'));
21 | app.use(bodyParser.json());
22 | app.use(bodyParser.urlencoded({extended: false}));
23 | app.use(cookieParser());
24 | app.use(express.static(path.join(__dirname, 'public')));
25 |
26 | app.use((req, res, next) => {
27 | let path = req.path; // 获取地址
28 | let whiteList = [
29 | '/apis/goods',
30 | '/apis/users/login',
31 | '/apis/users/logOut'
32 | ];
33 |
34 | if (req.cookies.loginUser) {
35 | next();
36 | } else {
37 | let flag = false;
38 | whiteList.forEach((item) => {
39 | if (item === path) {
40 | flag = true;
41 | }
42 | });
43 |
44 | if (flag) {
45 | next();
46 | } else {
47 | res.json({
48 | status: 2,
49 | msg: '用户未登录',
50 | result: ''
51 | });
52 | }
53 | }
54 | });
55 |
56 | app.use('/apis/goods', goods);
57 | app.use('/apis/users', users);
58 | app.use('/index', index);
59 |
60 | // catch 404 and forward to error handler
61 | app.use(function (req, res, next) {
62 | var err = new Error('Not Found');
63 | err.status = 404;
64 | next(err);
65 | });
66 |
67 | // error handler
68 | app.use(function (err, req, res, next) {
69 | // set locals, only providing error in development
70 | res.locals.message = err.message;
71 | res.locals.error = req.app.get('env') === 'development' ? err : {};
72 |
73 | // render the error page
74 | res.status(err.status || 500);
75 | res.render('error');
76 | });
77 |
78 | module.exports = app;
79 |
--------------------------------------------------------------------------------
/goods/build/utils.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const config = require('../config')
4 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
5 |
6 | exports.assetsPath = function (_path) {
7 | const assetsSubDirectory = process.env.NODE_ENV === 'production'
8 | ? config.build.assetsSubDirectory
9 | : config.dev.assetsSubDirectory
10 | return path.posix.join(assetsSubDirectory, _path)
11 | }
12 |
13 | exports.cssLoaders = function (options) {
14 | options = options || {}
15 |
16 | const cssLoader = {
17 | loader: 'css-loader',
18 | options: {
19 | minimize: process.env.NODE_ENV === 'production',
20 | sourceMap: options.sourceMap
21 | }
22 | }
23 |
24 | // generate loader string to be used with extract text plugin
25 | function generateLoaders (loader, loaderOptions) {
26 | const loaders = [cssLoader]
27 | if (loader) {
28 | loaders.push({
29 | loader: loader + '-loader',
30 | options: Object.assign({}, loaderOptions, {
31 | sourceMap: options.sourceMap
32 | })
33 | })
34 | }
35 |
36 | // Extract CSS when that option is specified
37 | // (which is the case during production build)
38 | if (options.extract) {
39 | return ExtractTextPlugin.extract({
40 | use: loaders,
41 | fallback: 'vue-style-loader'
42 | })
43 | } else {
44 | return ['vue-style-loader'].concat(loaders)
45 | }
46 | }
47 |
48 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html
49 | return {
50 | css: generateLoaders(),
51 | postcss: generateLoaders(),
52 | less: generateLoaders('less'),
53 | sass: generateLoaders('sass', { indentedSyntax: true }),
54 | scss: generateLoaders('sass'),
55 | stylus: generateLoaders('stylus'),
56 | styl: generateLoaders('stylus')
57 | }
58 | }
59 |
60 | // Generate loaders for standalone style files (outside of .vue)
61 | exports.styleLoaders = function (options) {
62 | const output = []
63 | const loaders = exports.cssLoaders(options)
64 | for (const extension in loaders) {
65 | const loader = loaders[extension]
66 | output.push({
67 | test: new RegExp('\\.' + extension + '$'),
68 | use: loader
69 | })
70 | }
71 | return output
72 | }
73 |
--------------------------------------------------------------------------------
/goods/src/base/confirm/confirm.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | {{ msg }}
7 |
8 |
12 |
13 |
14 |
15 |
16 |
54 |
55 |
93 |
--------------------------------------------------------------------------------
/goods/mock/goods.json:
--------------------------------------------------------------------------------
1 | {
2 | "status": "0",
3 | "msg": "",
4 | "result": [
5 | {
6 | "productId": "100001",
7 | "productName": "小米3",
8 | "salePrice": "2499",
9 | "productImage": "1.jpg"
10 | },
11 | {
12 | "productId": "100001",
13 | "productName": "小米4",
14 | "salePrice": "2399",
15 | "productImage": "2.jpg"
16 | },
17 | {
18 | "productId": "100001",
19 | "productName": "小米5",
20 | "salePrice": "2699",
21 | "productImage": "6.jpg"
22 | },
23 | {
24 | "productId": "100001",
25 | "productName": "小米6",
26 | "salePrice": "2199",
27 | "productImage": "4.jpg"
28 | },
29 | {
30 | "productId": "100001",
31 | "productName": "xxx",
32 | "salePrice": "1200",
33 | "productImage": "7.jpg"
34 | },
35 | {
36 | "productId": "100001",
37 | "productName": "yyy",
38 | "salePrice": "595",
39 | "productImage": "8.jpg"
40 | },
41 | {
42 | "productId": "100001",
43 | "productName": "yyy",
44 | "salePrice": "787",
45 | "productImage": "9.jpg"
46 | },
47 | {
48 | "productId": "100001",
49 | "productName": "yyy",
50 | "salePrice": "2345",
51 | "productImage": "10.jpg"
52 | },
53 | {
54 | "productId": "100001",
55 | "productName": "zzz",
56 | "salePrice": "2567",
57 | "productImage": "11.jpg"
58 | },
59 | {
60 | "productId": "100001",
61 | "productName": "vvv",
62 | "salePrice": "2842",
63 | "productImage": "12.jpg"
64 | },
65 | {
66 | "productId": "100001",
67 | "productName": "uuu",
68 | "salePrice": "2991",
69 | "productImage": "13.jpg"
70 | },
71 | {
72 | "productId": "100001",
73 | "productName": "jjj",
74 | "salePrice": "2471",
75 | "productImage": "14.jpg"
76 | },
77 | {
78 | "productId": "100001",
79 | "productName": "yyy",
80 | "salePrice": "1234",
81 | "productImage": "http://pic6.huitu.com/res/20130116/84481_20130116142820494200_1.jpg"
82 | },
83 | {
84 | "productId": "100001",
85 | "productName": "yyy",
86 | "salePrice": "3835",
87 | "productImage": "http://img2.imgtn.bdimg.com/it/u=4289577871,2613521315&fm=11&gp=0.jpg"
88 | }
89 | ]
90 | }
91 |
--------------------------------------------------------------------------------
/goods/demo/vue-resource.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
8 |
9 |
10 |
11 |
12 |
13 |
21 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/goods/src/components/order-success/order-success.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
下单成功!
5 |
6 | 订单号:{{ $route.query.orderId }}
7 | 订单费用:¥{{ formatM($route.query.orderTotal * 1) }}
8 |
9 |
13 |
14 |
15 |
16 |
34 |
35 |
107 |
--------------------------------------------------------------------------------
/goods/src/base/modal/modal.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | {{ title }}
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
35 |
36 |
112 |
--------------------------------------------------------------------------------
/goods/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "goods",
3 | "version": "1.0.0",
4 | "description": "vue & node & mongodb",
5 | "author": "weishuangjian <1607074855@qq.com>",
6 | "private": true,
7 | "scripts": {
8 | "dev": "node build/dev-server.js",
9 | "start": "npm run dev",
10 | "build": "node build/build.js",
11 | "lint": "eslint --ext .js,.vue src"
12 | },
13 | "dependencies": {
14 | "axios": "^0.16.2",
15 | "body-parser": "~1.18.2",
16 | "cookie-parser": "~1.4.3",
17 | "debug": "~2.6.9",
18 | "express": "~4.15.5",
19 | "jade": "~1.11.0",
20 | "mongoose": "^4.12.4",
21 | "morgan": "~1.9.0",
22 | "serve-favicon": "~2.4.5",
23 | "vue": "^2.5.2",
24 | "vue-infinite-scroll": "^2.0.2",
25 | "vue-lazyload": "^1.1.4",
26 | "vue-resource": "^1.3.4",
27 | "vue-router": "^3.0.1",
28 | "vuex": "^3.0.0"
29 | },
30 | "devDependencies": {
31 | "autoprefixer": "^7.1.2",
32 | "babel-core": "^6.22.1",
33 | "babel-eslint": "^7.1.1",
34 | "babel-loader": "^7.1.1",
35 | "babel-plugin-transform-runtime": "^6.22.0",
36 | "babel-preset-env": "^1.3.2",
37 | "babel-preset-stage-2": "^6.22.0",
38 | "babel-register": "^6.22.0",
39 | "chalk": "^2.0.1",
40 | "connect-history-api-fallback": "^1.3.0",
41 | "copy-webpack-plugin": "^4.0.1",
42 | "css-loader": "^0.28.0",
43 | "eslint": "^3.19.0",
44 | "eslint-config-standard": "^10.2.1",
45 | "eslint-friendly-formatter": "^3.0.0",
46 | "eslint-loader": "^1.7.1",
47 | "eslint-plugin-html": "^3.0.0",
48 | "eslint-plugin-import": "^2.7.0",
49 | "eslint-plugin-node": "^5.2.0",
50 | "eslint-plugin-promise": "^3.4.0",
51 | "eslint-plugin-standard": "^3.0.1",
52 | "eventsource-polyfill": "^0.9.6",
53 | "express": "^4.14.1",
54 | "extract-text-webpack-plugin": "^3.0.0",
55 | "file-loader": "^1.1.4",
56 | "friendly-errors-webpack-plugin": "^1.6.1",
57 | "html-webpack-plugin": "^2.30.1",
58 | "http-proxy-middleware": "^0.17.3",
59 | "less": "^3.0.0-alpha.3",
60 | "less-loader": "^4.0.5",
61 | "opn": "^5.1.0",
62 | "optimize-css-assets-webpack-plugin": "^3.2.0",
63 | "ora": "^1.2.0",
64 | "portfinder": "^1.0.13",
65 | "rimraf": "^2.6.0",
66 | "semver": "^5.3.0",
67 | "shelljs": "^0.7.6",
68 | "url-loader": "^0.5.8",
69 | "vue-loader": "^13.3.0",
70 | "vue-style-loader": "^3.0.1",
71 | "vue-template-compiler": "^2.5.2",
72 | "webpack": "^3.6.0",
73 | "webpack-bundle-analyzer": "^2.9.0",
74 | "webpack-dev-middleware": "^1.12.0",
75 | "webpack-hot-middleware": "^2.18.2",
76 | "webpack-merge": "^4.1.0"
77 | },
78 | "engines": {
79 | "node": ">= 4.0.0",
80 | "npm": ">= 3.0.0"
81 | },
82 | "browserslist": [
83 | "> 1%",
84 | "last 2 versions",
85 | "not ie <= 8"
86 | ]
87 | }
88 |
--------------------------------------------------------------------------------
/goods/demo/axios.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
8 |
9 |
10 |
34 |
35 |
36 |
44 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/goods/src/components/address/address.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{ orderTitle }}
4 |
5 | - 选择地址
6 | - 预览订单
7 | - 支付费用
8 | - 下单成功
9 |
10 |
11 |
12 |
13 |
14 |
74 |
75 |
124 |
--------------------------------------------------------------------------------
/goods/build/dev-server.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | const config = require('../config')
5 | if (!process.env.NODE_ENV) {
6 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
7 | }
8 |
9 | const opn = require('opn')
10 | const path = require('path')
11 | const express = require('express')
12 | const webpack = require('webpack')
13 | const proxyMiddleware = require('http-proxy-middleware')
14 | const webpackConfig = require('./webpack.dev.conf')
15 |
16 | // default port where dev server listens for incoming traffic
17 | const port = process.env.PORT || config.dev.port
18 | // automatically open browser, if not set will be false
19 | const autoOpenBrowser = !!config.dev.autoOpenBrowser
20 | // Define HTTP proxies to your custom API backend
21 | // https://github.com/chimurai/http-proxy-middleware
22 | const proxyTable = config.dev.proxyTable
23 |
24 | const app = express()
25 |
26 | // 模拟数据
27 | const router = express.Router();
28 | const goodsData = require('../mock/goods.json');
29 |
30 | router.get('/goods', (req, res, next) => {
31 | res.json(goodsData);
32 | });
33 |
34 | app.use('/api', router);
35 |
36 | const compiler = webpack(webpackConfig)
37 |
38 | const devMiddleware = require('webpack-dev-middleware')(compiler, {
39 | publicPath: webpackConfig.output.publicPath,
40 | quiet: true
41 | })
42 |
43 | const hotMiddleware = require('webpack-hot-middleware')(compiler, {
44 | log: false,
45 | heartbeat: 2000
46 | })
47 | // force page reload when html-webpack-plugin template changes
48 | // currently disabled until this is resolved:
49 | // https://github.com/jantimon/html-webpack-plugin/issues/680
50 | // compiler.plugin('compilation', function (compilation) {
51 | // compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
52 | // hotMiddleware.publish({ action: 'reload' })
53 | // cb()
54 | // })
55 | // })
56 |
57 | // enable hot-reload and state-preserving
58 | // compilation error display
59 | app.use(hotMiddleware)
60 |
61 | // proxy api requests
62 | Object.keys(proxyTable).forEach(function (context) {
63 | let options = proxyTable[context]
64 | if (typeof options === 'string') {
65 | options = { target: options }
66 | }
67 | app.use(proxyMiddleware(options.filter || context, options))
68 | })
69 |
70 | // handle fallback for HTML5 history API
71 | app.use(require('connect-history-api-fallback')())
72 |
73 | // serve webpack bundle output
74 | app.use(devMiddleware)
75 |
76 | // serve pure static assets
77 | const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
78 | app.use(staticPath, express.static('./static'))
79 |
80 | const uri = 'http://localhost:' + port
81 |
82 | var _resolve
83 | var _reject
84 | var readyPromise = new Promise((resolve, reject) => {
85 | _resolve = resolve
86 | _reject = reject
87 | })
88 |
89 | var server
90 | var portfinder = require('portfinder')
91 | portfinder.basePort = port
92 |
93 | console.log('> Starting dev server...')
94 | devMiddleware.waitUntilValid(() => {
95 | portfinder.getPort((err, port) => {
96 | if (err) {
97 | _reject(err)
98 | }
99 | process.env.PORT = port
100 | var uri = 'http://localhost:' + port
101 | console.log('> Listening at ' + uri + '\n')
102 | // when env is testing, don't need open it
103 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
104 | opn(uri)
105 | }
106 | server = app.listen(port)
107 | _resolve()
108 | })
109 | })
110 |
111 | module.exports = {
112 | ready: readyPromise,
113 | close: () => {
114 | server.close()
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/goods/build/webpack.prod.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const utils = require('./utils')
4 | const webpack = require('webpack')
5 | const config = require('../config')
6 | const merge = require('webpack-merge')
7 | const baseWebpackConfig = require('./webpack.base.conf')
8 | const CopyWebpackPlugin = require('copy-webpack-plugin')
9 | const HtmlWebpackPlugin = require('html-webpack-plugin')
10 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
11 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
12 |
13 | const env = config.build.env
14 |
15 | const webpackConfig = merge(baseWebpackConfig, {
16 | module: {
17 | rules: utils.styleLoaders({
18 | sourceMap: config.build.productionSourceMap,
19 | extract: true
20 | })
21 | },
22 | devtool: config.build.productionSourceMap ? '#source-map' : false,
23 | output: {
24 | path: config.build.assetsRoot,
25 | filename: utils.assetsPath('js/[name].[chunkhash].js'),
26 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
27 | },
28 | plugins: [
29 | // http://vuejs.github.io/vue-loader/en/workflow/production.html
30 | new webpack.DefinePlugin({
31 | 'process.env': env
32 | }),
33 | // UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minify
34 | new webpack.optimize.UglifyJsPlugin({
35 | compress: {
36 | warnings: false
37 | },
38 | sourceMap: true
39 | }),
40 | // extract css into its own file
41 | new ExtractTextPlugin({
42 | filename: utils.assetsPath('css/[name].[contenthash].css')
43 | }),
44 | // Compress extracted CSS. We are using this plugin so that possible
45 | // duplicated CSS from different components can be deduped.
46 | new OptimizeCSSPlugin({
47 | cssProcessorOptions: {
48 | safe: true
49 | }
50 | }),
51 | // generate dist index.html with correct asset hash for caching.
52 | // you can customize output by editing /index.html
53 | // see https://github.com/ampedandwired/html-webpack-plugin
54 | new HtmlWebpackPlugin({
55 | filename: config.build.index,
56 | template: 'index.html',
57 | inject: true,
58 | minify: {
59 | removeComments: true,
60 | collapseWhitespace: true,
61 | removeAttributeQuotes: true
62 | // more options:
63 | // https://github.com/kangax/html-minifier#options-quick-reference
64 | },
65 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin
66 | chunksSortMode: 'dependency'
67 | }),
68 | // keep module.id stable when vender modules does not change
69 | new webpack.HashedModuleIdsPlugin(),
70 | // split vendor js into its own file
71 | new webpack.optimize.CommonsChunkPlugin({
72 | name: 'vendor',
73 | minChunks: function (module) {
74 | // any required modules inside node_modules are extracted to vendor
75 | return (
76 | module.resource &&
77 | /\.js$/.test(module.resource) &&
78 | module.resource.indexOf(
79 | path.join(__dirname, '../node_modules')
80 | ) === 0
81 | )
82 | }
83 | }),
84 | // extract webpack runtime and module manifest to its own file in order to
85 | // prevent vendor hash from being updated whenever app bundle is updated
86 | new webpack.optimize.CommonsChunkPlugin({
87 | name: 'manifest',
88 | chunks: ['vendor']
89 | }),
90 | // copy custom static assets
91 | new CopyWebpackPlugin([
92 | {
93 | from: path.resolve(__dirname, '../static'),
94 | to: config.build.assetsSubDirectory,
95 | ignore: ['.*']
96 | }
97 | ])
98 | ]
99 | })
100 |
101 | if (config.build.productionGzip) {
102 | const CompressionWebpackPlugin = require('compression-webpack-plugin')
103 |
104 | webpackConfig.plugins.push(
105 | new CompressionWebpackPlugin({
106 | asset: '[path].gz[query]',
107 | algorithm: 'gzip',
108 | test: new RegExp(
109 | '\\.(' +
110 | config.build.productionGzipExtensions.join('|') +
111 | ')$'
112 | ),
113 | threshold: 10240,
114 | minRatio: 0.8
115 | })
116 | )
117 | }
118 |
119 | if (config.build.bundleAnalyzerReport) {
120 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
121 | webpackConfig.plugins.push(new BundleAnalyzerPlugin())
122 | }
123 |
124 | module.exports = webpackConfig
125 |
--------------------------------------------------------------------------------
/goods/server/routes/goods.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const mongoose = require('mongoose');
3 | const router = express.Router();
4 | const Goods = require('../models/goods');
5 | const User = require('../models/users');
6 | const Common = require('../public/javascripts/common');
7 |
8 | // 连接数据库
9 | mongoose.connect('mongodb://127.0.0.1:27017/db_demo');
10 |
11 | mongoose.connection.on('connected', function () {
12 | console.log('mongodb connected.');
13 | });
14 |
15 | // 获取商品数据
16 | router.post('/', function (req, res, next) {
17 | let query = req.body.params;
18 |
19 | let sort = parseInt(query.sort);
20 | let page = parseInt(query['page']);
21 | let pageSize = parseInt(query['size']);
22 | let skip = (page - 1) * pageSize;
23 | let ring = query['ring'];
24 |
25 | let params = {};
26 | if (ring) {
27 | params.salePrice = {
28 | $gte: ring.start,
29 | $lt: ring.end
30 | };
31 | }
32 |
33 | let goodsModel = Goods.find(params).skip(skip).limit(pageSize);
34 | if (sort) {
35 | goodsModel.sort({'salePrice': sort});
36 | }
37 |
38 | goodsModel.exec((err, doc) => {
39 | if (err) {
40 | Common.resInfo(res, 1, err.messgae, '');
41 | } else {
42 | Common.resInfo(res, 0, '', {
43 | count: doc.length,
44 | list: doc
45 | });
46 | }
47 | });
48 | });
49 |
50 | // 添加到购物车
51 | router.post('/addCar', (req, res, next) => {
52 | let userId = req.body.userId;
53 | let productId = req.body.productId;
54 |
55 | User.findOne({userId}, (err, userDoc) => {
56 | if (err) {
57 | Common.resInfo(res, 1, err.messgae, '');
58 | } else {
59 | Goods.findOne({productId}, (err, productDoc) => {
60 | if (err || !productDoc) {
61 | Common.resInfo(res, 1, err ? err.message : '数据不存在', '');
62 | } else {
63 | let exist = false;
64 | userDoc.cartList.forEach((item, index) => {
65 | if (item.productId === productId) {
66 | exist = true;
67 | userDoc.cartList[index].productNum++;
68 | }
69 | });
70 |
71 | if (!exist) {
72 | productDoc._doc.productNum = 1;
73 | productDoc._doc.checked = 1;
74 | userDoc.cartList.push(productDoc);
75 | }
76 |
77 | userDoc.save((err, saveDoc) => {
78 | if (err) {
79 | Common.resInfo(res, 1, err.messgae, '');
80 | } else {
81 | Common.resInfo(res, 0, '', {
82 | list: userDoc.cartList
83 | });
84 | }
85 | })
86 | ;
87 | }
88 | });
89 | }
90 | });
91 | });
92 |
93 | // 购物车
94 | router.post('/getGoods', (req, res, next) => {
95 | let userId = req.body.userId;
96 |
97 | User.findOne({userId}, (err, doc) => {
98 | if (err || !doc) {
99 | Common.resInfo(res, 1, err ? err.message : '暂无数据', '');
100 | } else {
101 | Common.resInfo(res, 0, '', {
102 | list: doc.cartList
103 | });
104 | }
105 | });
106 | });
107 |
108 | // 删除购物车数据
109 | router.post('/delCart', (req, res, next) => {
110 | let userId = req.body.userId;
111 | let productId = req.body.productId;
112 |
113 | User.update({userId: userId}, {
114 | $pull: {
115 | 'cartList': {
116 | 'productId': productId
117 | }
118 | }
119 | }, (err, doc) => {
120 | if (err) {
121 | Common.resInfo(res, 1, err.message, '');
122 | } else {
123 | Common.resInfo(res, 0, '', '');
124 | }
125 | });
126 | });
127 |
128 | // 更改购物车数据
129 | router.post('/setCart', (req, res, next) => {
130 | let userId = req.body.userId;
131 | let productId = req.body.productId === undefined ? '' : req.body.productId;
132 | let allChecked = req.body.allChecked === undefined ? '' : req.body.allChecked;
133 | let params = req.body.params;
134 |
135 | User.findOne({userId}, (err, userDoc) => {
136 | if (err || !userDoc) {
137 | Common.resInfo(res, 1, err ? err.message : '数据不存在', '');
138 | } else {
139 | userDoc.cartList.forEach((item) => {
140 | if (productId !== '' && item.productId === productId) {
141 | for (let key in params) {
142 | item[key] = params[key];
143 | }
144 | }
145 |
146 | if (allChecked !== '') {
147 | item.checked = allChecked;
148 | }
149 | });
150 |
151 | userDoc.save((err, doc) => {
152 | if (err || !doc) {
153 | Common.resInfo(res, 1, err ? err.message : '数据不存在', '');
154 | } else {
155 | Common.resInfo(res, 0, '', {
156 | list: doc.cartList
157 | });
158 | }
159 | });
160 | }
161 | });
162 | });
163 |
164 | module.exports = router;
165 |
--------------------------------------------------------------------------------
/goods/src/components/preview-order/preview-order.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
订单预览
4 |
5 |
6 | -
7 | 商品费用:
8 | ¥{{ formatM(goodsExpense) }}
9 |
10 | -
11 | 运费:
12 | ¥0.00
13 |
14 | -
15 | 优惠:
16 | ¥0.00
17 |
18 | -
19 | 总计:
20 | ¥{{ formatM(goodsExpense) }}
21 |
22 |
23 |
27 |
28 |
29 |
30 |
117 |
118 |
226 |
--------------------------------------------------------------------------------
/goods/server/routes/users.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const router = express.Router();
3 | const Mongoose = require('mongoose');
4 | const User = require('../models/users');
5 | const Common = require('../public/javascripts/common');
6 |
7 | Mongoose.connect('mongodb://127.0.0.1:27017/db_demo');
8 |
9 | // 登录
10 | router.post('/login', (req, res, next) => {
11 | let params = req.body;
12 |
13 | User.findOne({
14 | userName: params.userName,
15 | userPwd: params.userPwd
16 | }, (err, doc) => {
17 | if (err || !doc) {
18 | Common.resInfo(res, 1, err ? err.message : '用户名或密码错误', '');
19 | } else {
20 | res.cookie('loginUser', {
21 | userId: doc.userId,
22 | userName: doc.userName
23 | }, {
24 | path: '/',
25 | maxAge: 1000 * 60 * 60
26 | });
27 |
28 | Common.resInfo(res, 0, '', {
29 | userId: doc.userId,
30 | userName: doc.userName,
31 | cartList: doc.cartList,
32 | addressList: doc.addressList
33 | });
34 | }
35 | });
36 | });
37 |
38 | // 退出登录
39 | router.post('/logOut', (req, res, next) => {
40 | res.clearCookie('loginUser');
41 | Common.resInfo(res, 0, '', '');
42 | });
43 |
44 | // 检查是否登录
45 | router.post('/checkLog', (req, res, next) => {
46 | let logUser = req.cookies.loginUser;
47 |
48 | if (logUser) {
49 | User.findOne({
50 | userId: logUser.userId
51 | }, (err, doc) => {
52 | if (err || !doc) {
53 | Common.resInfo(res, 1, err ? err.message : '用户不存在', '');
54 | } else {
55 | Common.resInfo(res, 0, '', {
56 | userId: doc.userId,
57 | userName: doc.userName,
58 | cartList: doc.cartList,
59 | addressList: doc.addressList
60 | });
61 | }
62 | });
63 | } else {
64 | Common.resInfo(res, 1, '用户不存在', '');
65 | }
66 | });
67 |
68 | // 添加地址
69 | router.post('/addAddress', (req, res, next) => {
70 | let userId = req.body.userId;
71 | let address = req.body.address;
72 |
73 | if (address) {
74 | address.isDefault = false;
75 | address.addressId = new Date().getTime();
76 | }
77 |
78 | User.findOne({userId}, (err, userDoc) => {
79 | if (err || !userDoc) {
80 | Common.resInfo(res, 1, err ? err.message : '用户不存在', '');
81 | } else {
82 | userDoc.addressList.push(address);
83 |
84 | userDoc.save((err, saveDoc) => {
85 | if (err) {
86 | Common.resInfo(res, 1, err.message, '');
87 | } else {
88 | Common.resInfo(res, 0, '', {
89 | addressList: saveDoc.addressList
90 | });
91 | }
92 | });
93 | }
94 | });
95 | });
96 |
97 | // 删除地址
98 | router.post('/delAddress', (req, res, next) => {
99 | let userId = req.body.userId;
100 | let addressId = req.body.addressId;
101 |
102 | User.update({userId}, {
103 | $pull: {
104 | addressList: {
105 | addressId
106 | }
107 | }
108 | }, (err, doc) => {
109 | if (err || !doc) {
110 | Common.resInfo(res, 1, err ? err.messgae : '数据不存在', '');
111 | } else {
112 | User.findOne({userId}, (err, userDoc) => {
113 | if (err || !userDoc) {
114 | Common.resInfo(res, 1, err ? err.messgae : '用户不存在', '');
115 | } else {
116 | Common.resInfo(res, 0, '', {
117 | addressList: userDoc.addressList
118 | });
119 | }
120 | });
121 | }
122 | });
123 | });
124 |
125 | // 修改地址
126 | router.post('/editAddress', (req, res, next) => {
127 | let userId = req.body.userId;
128 | let addressId = req.body.addressId;
129 | let addrDefault = req.body.addrDefault;
130 | let params = req.body.params;
131 |
132 | User.findOne({userId}, (err, userDoc) => {
133 | if (err || !userDoc) {
134 | Common.resInfo(res, 1, err ? err.messgae : '用户不存在', '');
135 | } else {
136 | if (addrDefault === undefined) {
137 | userDoc.addressList.forEach((item) => {
138 | if (item.addressId === addressId) {
139 | for (let k in params) {
140 | item[k] = params[k];
141 | }
142 | }
143 | });
144 | } else {
145 | userDoc.addressList.forEach((item) => {
146 | if (item.addressId === addressId) {
147 | item.isDefault = true;
148 | } else {
149 | item.isDefault = false;
150 | }
151 | });
152 | }
153 |
154 | userDoc.save((err, saveDoc) => {
155 | if (err) {
156 | Common.resInfo(res, 1, err.message, '');
157 | } else {
158 | Common.resInfo(res, 0, '', {
159 | addressList: saveDoc.addressList
160 | });
161 | }
162 | });
163 | }
164 | });
165 | });
166 |
167 | // 检测是否地址是否存在
168 | router.post('/existAddr', (req, res, next) => {
169 | let userId = req.body.userId;
170 | let addressId = req.body.addressId;
171 |
172 | User.findOne({userId}, (err, userDoc) => {
173 | if (err || !userDoc) {
174 | Common.resInfo(res, 1, err ? err.message : '数据不存在', '');
175 | } else {
176 | let addr;
177 |
178 | userDoc.addressList.forEach((item) => {
179 | if (item.addressId === addressId) {
180 | addr = item;
181 | }
182 | });
183 |
184 | if (addr) {
185 | Common.resInfo(res, 0, '', {
186 | addressInfo: addr,
187 | cartList: userDoc.cartList
188 | });
189 | } else {
190 | Common.resInfo(res, 1, '数据不存在', '');
191 | }
192 | }
193 | });
194 | });
195 |
196 | // 添加订单
197 | router.post('/addOrder', (req, res, next) => {
198 | let userId = req.body.userId;
199 | let params = req.body.params;
200 | let orderId = new Date().getTime().toString();
201 | let randomNum = Math.ceil(Math.random() * 9000 + 1000);
202 |
203 | params.createDate = new Date().toLocaleString();
204 | params.orderId = orderId + randomNum;
205 | params.orderStatus = 1;
206 |
207 | User.findOne({userId}, (err, userDoc) => {
208 | if (err || !userDoc) {
209 | Common.resInfo(res, 1, err ? err.message : '数据不存在', '');
210 | } else {
211 | userDoc.orderList.push(params);
212 | userDoc.save((err) => {
213 | if (err) {
214 | Common.resInfo(res, 1, err.message, '');
215 | } else {
216 | Common.resInfo(res, 0, '', {
217 | orderId: params.orderId
218 | });
219 | }
220 | });
221 | }
222 | });
223 | });
224 |
225 | module.exports = router;
226 |
--------------------------------------------------------------------------------
/goods/src/base/goods-list/goods-list.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
![]()
14 |
{{ item.productName }}
15 |
16 | ¥{{ formatM(item.salePrice * 1) }}
17 |
18 |
19 | ×{{ item.productNum }}
20 |
21 | ¥{{ formatM(item.productNum * item.salePrice) }}
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
70 |
71 |
249 |
--------------------------------------------------------------------------------
/goods/src/components/header/header.vue:
--------------------------------------------------------------------------------
1 |
2 |
38 |
39 |
40 |
152 |
153 |
326 |
--------------------------------------------------------------------------------
/goods/static/reset.css:
--------------------------------------------------------------------------------
1 | /*! normalize.css v7.0.0 | MIT License | github.com/necolas/normalize.css */
2 |
3 | /* Document
4 | ========================================================================== */
5 |
6 | /**
7 | * 1. Correct the line height in all browsers.
8 | * 2. Prevent adjustments of font size after orientation changes in
9 | * IE on Windows Phone and in iOS.
10 | */
11 |
12 | html {
13 | line-height: 1.15; /* 1 */
14 | -ms-text-size-adjust: 100%; /* 2 */
15 | -webkit-text-size-adjust: 100%; /* 2 */
16 | }
17 |
18 | /* Sections
19 | ========================================================================== */
20 |
21 | /**
22 | * Remove the margin in all browsers (opinionated).
23 | */
24 |
25 | body {
26 | margin: 0;
27 | font-family: 'Microsoft Yahei';
28 | background-color: #f5f7fc;
29 | }
30 |
31 | /**
32 | * Add the correct display in IE 9-.
33 | */
34 |
35 | article,
36 | aside,
37 | footer,
38 | header,
39 | nav,
40 | section {
41 | display: block;
42 | }
43 |
44 | /**
45 | * Correct the font size and margin on `h1` elements within `section` and
46 | * `article` contexts in Chrome, Firefox, and Safari.
47 | */
48 |
49 | h1 {
50 | font-size: 2em;
51 | margin: 0.67em 0;
52 | }
53 |
54 | html,
55 | body,
56 | p,
57 | ol,
58 | ul,
59 | li,
60 | dl,
61 | dt,
62 | dd,
63 | blockquote,
64 | figure,
65 | fieldset,
66 | legend,
67 | textarea,
68 | pre,
69 | iframe,
70 | hr,
71 | h1,
72 | h2,
73 | h3,
74 | h4,
75 | h5,
76 | h6 {
77 | margin: 0;
78 | padding: 0;
79 | }
80 |
81 | ul, li {
82 | list-style: none;
83 | }
84 |
85 | /* Grouping content
86 | ========================================================================== */
87 |
88 | /**
89 | * Add the correct display in IE 9-.
90 | * 1. Add the correct display in IE.
91 | */
92 |
93 | figcaption,
94 | figure,
95 | main { /* 1 */
96 | display: block;
97 | }
98 |
99 | /**
100 | * Add the correct margin in IE 8.
101 | */
102 |
103 | figure {
104 | margin: 1em 40px;
105 | }
106 |
107 | /**
108 | * 1. Add the correct box sizing in Firefox.
109 | * 2. Show the overflow in Edge and IE.
110 | */
111 |
112 | hr {
113 | box-sizing: content-box; /* 1 */
114 | height: 0; /* 1 */
115 | overflow: visible; /* 2 */
116 | }
117 |
118 | /**
119 | * 1. Correct the inheritance and scaling of font size in all browsers.
120 | * 2. Correct the odd `em` font sizing in all browsers.
121 | */
122 |
123 | pre {
124 | font-family: monospace, monospace; /* 1 */
125 | font-size: 1em; /* 2 */
126 | }
127 |
128 | /* Text-level semantics
129 | ========================================================================== */
130 |
131 | /**
132 | * 1. Remove the gray background on active links in IE 10.
133 | * 2. Remove gaps in links underline in iOS 8+ and Safari 8+.
134 | */
135 |
136 | a {
137 | background-color: transparent; /* 1 */
138 | -webkit-text-decoration-skip: objects; /* 2 */
139 | text-decoration: none;
140 | }
141 |
142 | /**
143 | * 1. Remove the bottom border in Chrome 57- and Firefox 39-.
144 | * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
145 | */
146 |
147 | abbr[title] {
148 | border-bottom: none; /* 1 */
149 | text-decoration: underline; /* 2 */
150 | text-decoration: underline dotted; /* 2 */
151 | }
152 |
153 | /**
154 | * Prevent the duplicate application of `bolder` by the next rule in Safari 6.
155 | */
156 |
157 | b,
158 | strong {
159 | font-weight: inherit;
160 | }
161 |
162 | /**
163 | * Add the correct font weight in Chrome, Edge, and Safari.
164 | */
165 |
166 | b,
167 | strong {
168 | font-weight: bolder;
169 | }
170 |
171 | /**
172 | * 1. Correct the inheritance and scaling of font size in all browsers.
173 | * 2. Correct the odd `em` font sizing in all browsers.
174 | */
175 |
176 | code,
177 | kbd,
178 | samp {
179 | font-family: monospace, monospace; /* 1 */
180 | font-size: 1em; /* 2 */
181 | }
182 |
183 | /**
184 | * Add the correct font style in Android 4.3-.
185 | */
186 |
187 | dfn {
188 | font-style: italic;
189 | }
190 |
191 | /**
192 | * Add the correct background and color in IE 9-.
193 | */
194 |
195 | mark {
196 | background-color: #ff0;
197 | color: #000;
198 | }
199 |
200 | /**
201 | * Add the correct font size in all browsers.
202 | */
203 |
204 | small {
205 | font-size: 80%;
206 | }
207 |
208 | /**
209 | * Prevent `sub` and `sup` elements from affecting the line height in
210 | * all browsers.
211 | */
212 |
213 | sub,
214 | sup {
215 | font-size: 75%;
216 | line-height: 0;
217 | position: relative;
218 | vertical-align: baseline;
219 | }
220 |
221 | sub {
222 | bottom: -0.25em;
223 | }
224 |
225 | sup {
226 | top: -0.5em;
227 | }
228 |
229 | /* Embedded content
230 | ========================================================================== */
231 |
232 | /**
233 | * Add the correct display in IE 9-.
234 | */
235 |
236 | audio,
237 | video {
238 | display: inline-block;
239 | }
240 |
241 | /**
242 | * Add the correct display in iOS 4-7.
243 | */
244 |
245 | audio:not([controls]) {
246 | display: none;
247 | height: 0;
248 | }
249 |
250 | /**
251 | * Remove the border on images inside links in IE 10-.
252 | */
253 |
254 | img {
255 | border-style: none;
256 | }
257 |
258 | /**
259 | * Hide the overflow in IE.
260 | */
261 |
262 | svg:not(:root) {
263 | overflow: hidden;
264 | }
265 |
266 | /* Forms
267 | ========================================================================== */
268 |
269 | /**
270 | * 1. Change the font styles in all browsers (opinionated).
271 | * 2. Remove the margin in Firefox and Safari.
272 | */
273 |
274 | button,
275 | input,
276 | optgroup,
277 | select,
278 | textarea {
279 | font-family: sans-serif; /* 1 */
280 | font-size: 100%; /* 1 */
281 | line-height: 1.15; /* 1 */
282 | margin: 0; /* 2 */
283 | }
284 |
285 | /**
286 | * Show the overflow in IE.
287 | * 1. Show the overflow in Edge.
288 | */
289 |
290 | button,
291 | input { /* 1 */
292 | overflow: visible;
293 | }
294 |
295 | /**
296 | * Remove the inheritance of text transform in Edge, Firefox, and IE.
297 | * 1. Remove the inheritance of text transform in Firefox.
298 | */
299 |
300 | button,
301 | select { /* 1 */
302 | text-transform: none;
303 | }
304 |
305 | /**
306 | * 1. Prevent a WebKit bug where (2) destroys native `audio` and `video`
307 | * controls in Android 4.
308 | * 2. Correct the inability to style clickable types in iOS and Safari.
309 | */
310 |
311 | button,
312 | html [type="button"], /* 1 */
313 | [type="reset"],
314 | [type="submit"] {
315 | -webkit-appearance: button; /* 2 */
316 | }
317 |
318 | /**
319 | * Remove the inner border and padding in Firefox.
320 | */
321 |
322 | button::-moz-focus-inner,
323 | [type="button"]::-moz-focus-inner,
324 | [type="reset"]::-moz-focus-inner,
325 | [type="submit"]::-moz-focus-inner {
326 | border-style: none;
327 | padding: 0;
328 | }
329 |
330 | /**
331 | * Restore the focus styles unset by the previous rule.
332 | */
333 |
334 | button:-moz-focusring,
335 | [type="button"]:-moz-focusring,
336 | [type="reset"]:-moz-focusring,
337 | [type="submit"]:-moz-focusring {
338 | outline: 1px dotted ButtonText;
339 | }
340 |
341 | /**
342 | * Correct the padding in Firefox.
343 | */
344 |
345 | fieldset {
346 | padding: 0.35em 0.75em 0.625em;
347 | }
348 |
349 | /**
350 | * 1. Correct the text wrapping in Edge and IE.
351 | * 2. Correct the color inheritance from `fieldset` elements in IE.
352 | * 3. Remove the padding so developers are not caught out when they zero out
353 | * `fieldset` elements in all browsers.
354 | */
355 |
356 | legend {
357 | box-sizing: border-box; /* 1 */
358 | color: inherit; /* 2 */
359 | display: table; /* 1 */
360 | max-width: 100%; /* 1 */
361 | padding: 0; /* 3 */
362 | white-space: normal; /* 1 */
363 | }
364 |
365 | /**
366 | * 1. Add the correct display in IE 9-.
367 | * 2. Add the correct vertical alignment in Chrome, Firefox, and Opera.
368 | */
369 |
370 | progress {
371 | display: inline-block; /* 1 */
372 | vertical-align: baseline; /* 2 */
373 | }
374 |
375 | /**
376 | * Remove the default vertical scrollbar in IE.
377 | */
378 |
379 | textarea {
380 | overflow: auto;
381 | }
382 |
383 | /**
384 | * 1. Add the correct box sizing in IE 10-.
385 | * 2. Remove the padding in IE 10-.
386 | */
387 |
388 | [type="checkbox"],
389 | [type="radio"] {
390 | box-sizing: border-box; /* 1 */
391 | padding: 0; /* 2 */
392 | }
393 |
394 | /**
395 | * Correct the cursor style of increment and decrement buttons in Chrome.
396 | */
397 |
398 | [type="number"]::-webkit-inner-spin-button,
399 | [type="number"]::-webkit-outer-spin-button {
400 | height: auto;
401 | }
402 |
403 | /**
404 | * 1. Correct the odd appearance in Chrome and Safari.
405 | * 2. Correct the outline style in Safari.
406 | */
407 |
408 | [type="search"] {
409 | -webkit-appearance: textfield; /* 1 */
410 | outline-offset: -2px; /* 2 */
411 | }
412 |
413 | /**
414 | * Remove the inner padding and cancel buttons in Chrome and Safari on macOS.
415 | */
416 |
417 | [type="search"]::-webkit-search-cancel-button,
418 | [type="search"]::-webkit-search-decoration {
419 | -webkit-appearance: none;
420 | }
421 |
422 | /**
423 | * 1. Correct the inability to style clickable types in iOS and Safari.
424 | * 2. Change font properties to `inherit` in Safari.
425 | */
426 |
427 | ::-webkit-file-upload-button {
428 | -webkit-appearance: button; /* 1 */
429 | font: inherit; /* 2 */
430 | }
431 |
432 | /* Interactive
433 | ========================================================================== */
434 |
435 | /*
436 | * Add the correct display in IE 9-.
437 | * 1. Add the correct display in Edge, IE, and Firefox.
438 | */
439 |
440 | details, /* 1 */
441 | menu {
442 | display: block;
443 | }
444 |
445 | /*
446 | * Add the correct display in all browsers.
447 | */
448 |
449 | summary {
450 | display: list-item;
451 | }
452 |
453 | /* Scripting
454 | ========================================================================== */
455 |
456 | /**
457 | * Add the correct display in IE 9-.
458 | */
459 |
460 | canvas {
461 | display: inline-block;
462 | }
463 |
464 | /**
465 | * Add the correct display in IE.
466 | */
467 |
468 | template {
469 | display: none;
470 | }
471 |
472 | /* Hidden
473 | ========================================================================== */
474 |
475 | /**
476 | * Add the correct display in IE 10-.
477 | */
478 |
479 | [hidden] {
480 | display: none;
481 | }
482 |
--------------------------------------------------------------------------------
/goods/src/components/cart/cart.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
我的购物车
4 |
我的购物车
5 |
7 |
8 |
9 |
10 | 全选
11 |
12 |
13 |
总价:
14 |
¥{{ formatM(totalPrice) }}
15 |
提交订单
16 |
17 |
18 |
19 |
20 |
21 |
22 |
185 |
186 |
406 |
--------------------------------------------------------------------------------
/goods/src/components/select-address/select-address.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
配送地址
5 |
6 |
11 | {{ address.userName }}
12 | {{ address.streetName }}
13 | {{ address.tel }}
14 |
15 | 设置为默认地址
16 | 默认地址
17 | 删除
18 |
19 |
20 |
21 | 添加
22 | 点击添加新地址
23 |
24 |
25 |
28 |
29 |
41 |
44 |
45 |
46 |
47 |
49 |
51 |
53 |
55 |
56 |
59 |
60 |
61 |
62 |
63 |
241 |
242 |
505 |
--------------------------------------------------------------------------------
/goods/src/components/goods/goods.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
商品
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | - 价格区间:
20 | - ALL
21 | -
23 | {{ item.start.toFixed(2) }} - {{ item.end.toFixed(2) }}
24 |
25 |
26 |
27 |
28 | -
29 |
30 |
31 |
32 | {{ item.productName }}
33 | ¥ {{ formatM(item.salePrice * 1) }}
34 | 加入购物车
35 |
36 |
37 |
38 |
40 |
41 |
42 |
43 |
44 |
50 |
51 |
52 |
53 |
210 |
211 |
564 |
--------------------------------------------------------------------------------