
32 changed files with 1692 additions and 21 deletions
Binary file not shown.
@ -0,0 +1,35 @@ |
|||
require('./check-versions')() |
|||
|
|||
process.env.NODE_ENV = 'production' |
|||
|
|||
var ora = require('ora') |
|||
var rm = require('rimraf') |
|||
var path = require('path') |
|||
var chalk = require('chalk') |
|||
var webpack = require('webpack') |
|||
var config = require('../config') |
|||
var webpackConfig = require('./webpack.prod.conf') |
|||
|
|||
var spinner = ora('building for production...') |
|||
spinner.start() |
|||
|
|||
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { |
|||
if (err) throw err |
|||
webpack(webpackConfig, function (err, stats) { |
|||
spinner.stop() |
|||
if (err) throw err |
|||
process.stdout.write(stats.toString({ |
|||
colors: true, |
|||
modules: false, |
|||
children: false, |
|||
chunks: false, |
|||
chunkModules: false |
|||
}) + '\n\n') |
|||
|
|||
console.log(chalk.cyan(' Build complete.\n')) |
|||
console.log(chalk.yellow( |
|||
' Tip: built files are meant to be served over an HTTP server.\n' + |
|||
' Opening index.html over file:// won\'t work.\n' |
|||
)) |
|||
}) |
|||
}) |
@ -0,0 +1,48 @@ |
|||
var chalk = require('chalk') |
|||
var semver = require('semver') |
|||
var packageConfig = require('../package.json') |
|||
var shell = require('shelljs') |
|||
function exec (cmd) { |
|||
return require('child_process').execSync(cmd).toString().trim() |
|||
} |
|||
|
|||
var versionRequirements = [ |
|||
{ |
|||
name: 'node', |
|||
currentVersion: semver.clean(process.version), |
|||
versionRequirement: packageConfig.engines.node |
|||
}, |
|||
] |
|||
|
|||
if (shell.which('npm')) { |
|||
versionRequirements.push({ |
|||
name: 'npm', |
|||
currentVersion: exec('npm --version'), |
|||
versionRequirement: packageConfig.engines.npm |
|||
}) |
|||
} |
|||
|
|||
module.exports = function () { |
|||
var warnings = [] |
|||
for (var i = 0; i < versionRequirements.length; i++) { |
|||
var mod = versionRequirements[i] |
|||
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { |
|||
warnings.push(mod.name + ': ' + |
|||
chalk.red(mod.currentVersion) + ' should be ' + |
|||
chalk.green(mod.versionRequirement) |
|||
) |
|||
} |
|||
} |
|||
|
|||
if (warnings.length) { |
|||
console.log('') |
|||
console.log(chalk.yellow('To use this template, you must update following to modules:')) |
|||
console.log() |
|||
for (var i = 0; i < warnings.length; i++) { |
|||
var warning = warnings[i] |
|||
console.log(' ' + warning) |
|||
} |
|||
console.log() |
|||
process.exit(1) |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
/* eslint-disable */ |
|||
require('eventsource-polyfill') |
|||
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') |
|||
|
|||
hotClient.subscribe(function (event) { |
|||
if (event.action === 'reload') { |
|||
window.location.reload() |
|||
} |
|||
}) |
@ -0,0 +1,89 @@ |
|||
require('./check-versions')() |
|||
|
|||
var config = require('../config') |
|||
if (!process.env.NODE_ENV) { |
|||
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) |
|||
} |
|||
|
|||
var opn = require('opn') |
|||
var path = require('path') |
|||
var express = require('express') |
|||
var webpack = require('webpack') |
|||
var proxyMiddleware = require('http-proxy-middleware') |
|||
var webpackConfig = require('./webpack.dev.conf') |
|||
|
|||
// default port where dev server listens for incoming traffic
|
|||
var port = process.env.PORT || config.dev.port |
|||
// automatically open browser, if not set will be false
|
|||
var autoOpenBrowser = !!config.dev.autoOpenBrowser |
|||
// Define HTTP proxies to your custom API backend
|
|||
// https://github.com/chimurai/http-proxy-middleware
|
|||
var proxyTable = config.dev.proxyTable |
|||
|
|||
var app = express() |
|||
var compiler = webpack(webpackConfig) |
|||
|
|||
var devMiddleware = require('webpack-dev-middleware')(compiler, { |
|||
publicPath: webpackConfig.output.publicPath, |
|||
quiet: true |
|||
}) |
|||
|
|||
var hotMiddleware = require('webpack-hot-middleware')(compiler, { |
|||
log: () => {} |
|||
}) |
|||
// force page reload when html-webpack-plugin template changes
|
|||
compiler.plugin('compilation', function (compilation) { |
|||
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { |
|||
hotMiddleware.publish({ action: 'reload' }) |
|||
cb() |
|||
}) |
|||
}) |
|||
|
|||
// proxy api requests
|
|||
Object.keys(proxyTable).forEach(function (context) { |
|||
var options = proxyTable[context] |
|||
if (typeof options === 'string') { |
|||
options = { target: options } |
|||
} |
|||
app.use(proxyMiddleware(options.filter || context, options)) |
|||
}) |
|||
|
|||
// handle fallback for HTML5 history API
|
|||
app.use(require('connect-history-api-fallback')()) |
|||
|
|||
// serve webpack bundle output
|
|||
app.use(devMiddleware) |
|||
|
|||
// enable hot-reload and state-preserving
|
|||
// compilation error display
|
|||
app.use(hotMiddleware) |
|||
|
|||
// serve pure static assets
|
|||
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) |
|||
app.use(staticPath, express.static('./static')) |
|||
|
|||
var uri = 'http://127.0.0.1:' + port |
|||
|
|||
var _resolve |
|||
var readyPromise = new Promise(resolve => { |
|||
_resolve = resolve |
|||
}) |
|||
|
|||
console.log('> Starting dev server...') |
|||
devMiddleware.waitUntilValid(() => { |
|||
console.log('> Listening at ' + uri + '\n') |
|||
// when env is testing, don't need open it
|
|||
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { |
|||
opn(uri) |
|||
} |
|||
_resolve() |
|||
}) |
|||
|
|||
var server = app.listen(port) |
|||
|
|||
module.exports = { |
|||
ready: readyPromise, |
|||
close: () => { |
|||
server.close() |
|||
} |
|||
} |
@ -0,0 +1,71 @@ |
|||
var path = require('path') |
|||
var config = require('../config') |
|||
var ExtractTextPlugin = require('extract-text-webpack-plugin') |
|||
|
|||
exports.assetsPath = function (_path) { |
|||
var assetsSubDirectory = process.env.NODE_ENV === 'production' |
|||
? config.build.assetsSubDirectory |
|||
: config.dev.assetsSubDirectory |
|||
return path.posix.join(assetsSubDirectory, _path) |
|||
} |
|||
|
|||
exports.cssLoaders = function (options) { |
|||
options = options || {} |
|||
|
|||
var cssLoader = { |
|||
loader: 'css-loader', |
|||
options: { |
|||
minimize: process.env.NODE_ENV === 'production', |
|||
sourceMap: options.sourceMap |
|||
} |
|||
} |
|||
|
|||
// generate loader string to be used with extract text plugin
|
|||
function generateLoaders (loader, loaderOptions) { |
|||
var loaders = [cssLoader] |
|||
if (loader) { |
|||
loaders.push({ |
|||
loader: loader + '-loader', |
|||
options: Object.assign({}, loaderOptions, { |
|||
sourceMap: options.sourceMap |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
// Extract CSS when that option is specified
|
|||
// (which is the case during production build)
|
|||
if (options.extract) { |
|||
return ExtractTextPlugin.extract({ |
|||
use: loaders, |
|||
fallback: 'vue-style-loader' |
|||
}) |
|||
} else { |
|||
return ['vue-style-loader'].concat(loaders) |
|||
} |
|||
} |
|||
|
|||
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
|
|||
return { |
|||
css: generateLoaders(), |
|||
postcss: generateLoaders(), |
|||
less: generateLoaders('less'), |
|||
sass: generateLoaders('sass', { indentedSyntax: true }), |
|||
scss: generateLoaders('sass'), |
|||
stylus: generateLoaders('stylus'), |
|||
styl: generateLoaders('stylus') |
|||
} |
|||
} |
|||
|
|||
// Generate loaders for standalone style files (outside of .vue)
|
|||
exports.styleLoaders = function (options) { |
|||
var output = [] |
|||
var loaders = exports.cssLoaders(options) |
|||
for (var extension in loaders) { |
|||
var loader = loaders[extension] |
|||
output.push({ |
|||
test: new RegExp('\\.' + extension + '$'), |
|||
use: loader |
|||
}) |
|||
} |
|||
return output |
|||
} |
@ -0,0 +1,12 @@ |
|||
var utils = require('./utils') |
|||
var config = require('../config') |
|||
var isProduction = process.env.NODE_ENV === 'production' |
|||
|
|||
module.exports = { |
|||
loaders: utils.cssLoaders({ |
|||
sourceMap: isProduction |
|||
? config.build.productionSourceMap |
|||
: config.dev.cssSourceMap, |
|||
extract: isProduction |
|||
}) |
|||
} |
@ -0,0 +1,74 @@ |
|||
var path = require('path') |
|||
var utils = require('./utils') |
|||
var config = require('../config') |
|||
var vueLoaderConfig = require('./vue-loader.conf') |
|||
|
|||
function resolve (dir) { |
|||
return path.join(__dirname, '..', dir) |
|||
} |
|||
|
|||
module.exports = { |
|||
// webpack打包时排除以下js依赖 需手动加入js
|
|||
// externals: {
|
|||
// 'vue': 'Vue',
|
|||
// 'vue-router': 'VueRouter',
|
|||
// 'vuex': 'Vuex',
|
|||
// 'axios': 'axios'
|
|||
// },
|
|||
entry: { |
|||
app: './src/main.js' |
|||
}, |
|||
output: { |
|||
path: config.build.assetsRoot, |
|||
filename: '[name].js', |
|||
publicPath: process.env.NODE_ENV === 'production' |
|||
? config.build.assetsPublicPath |
|||
: config.dev.assetsPublicPath |
|||
}, |
|||
resolve: { |
|||
extensions: ['.js', '.vue', '.json'], |
|||
alias: { |
|||
'@': resolve('src'), |
|||
'/components': resolve('src/components'), |
|||
'/page': resolve('src/page'), |
|||
'/common': resolve('src/common'), |
|||
'/assets': resolve('src/assets'), |
|||
'/api': resolve('src/api'), |
|||
'/utils': resolve('src/utils') |
|||
} |
|||
}, |
|||
module: { |
|||
rules: [ |
|||
|
|||
{ |
|||
test: /\.vue$/, |
|||
loader: 'vue-loader', |
|||
options: vueLoaderConfig |
|||
}, { |
|||
test: /\.scss$/, |
|||
loaders: ['style', 'css', 'sass'] |
|||
}, |
|||
{ |
|||
test: /\.js$/, |
|||
loader: 'babel-loader', |
|||
include: [resolve('src'), resolve('test')] |
|||
}, |
|||
{ |
|||
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, |
|||
loader: 'url-loader', |
|||
options: { |
|||
limit: 10000, |
|||
name: utils.assetsPath('img/[name].[hash:7].[ext]') |
|||
} |
|||
}, |
|||
{ |
|||
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, |
|||
loader: 'url-loader', |
|||
options: { |
|||
limit: 10000, |
|||
name: utils.assetsPath('fonts/[name].[hash:7].[ext]') |
|||
} |
|||
} |
|||
] |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
var utils = require('./utils') |
|||
var webpack = require('webpack') |
|||
var config = require('../config') |
|||
var merge = require('webpack-merge') |
|||
var baseWebpackConfig = require('./webpack.base.conf') |
|||
var HtmlWebpackPlugin = require('html-webpack-plugin') |
|||
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') |
|||
|
|||
// add hot-reload related code to entry chunks
|
|||
Object.keys(baseWebpackConfig.entry).forEach(function (name) { |
|||
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) |
|||
}) |
|||
|
|||
module.exports = merge(baseWebpackConfig, { |
|||
module: { |
|||
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) |
|||
}, |
|||
// cheap-module-eval-source-map is faster for development
|
|||
devtool: '#cheap-module-eval-source-map', |
|||
plugins: [ |
|||
new webpack.DefinePlugin({ |
|||
'process.env': config.dev.env |
|||
}), |
|||
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
|
|||
new webpack.HotModuleReplacementPlugin(), |
|||
new webpack.NoEmitOnErrorsPlugin(), |
|||
// https://github.com/ampedandwired/html-webpack-plugin
|
|||
new HtmlWebpackPlugin({ |
|||
filename: 'index.html', |
|||
template: 'index.html', |
|||
inject: true |
|||
}), |
|||
new FriendlyErrorsPlugin() |
|||
] |
|||
}) |
@ -0,0 +1,120 @@ |
|||
var path = require('path') |
|||
var utils = require('./utils') |
|||
var webpack = require('webpack') |
|||
var config = require('../config') |
|||
var merge = require('webpack-merge') |
|||
var baseWebpackConfig = require('./webpack.base.conf') |
|||
var CopyWebpackPlugin = require('copy-webpack-plugin') |
|||
var HtmlWebpackPlugin = require('html-webpack-plugin') |
|||
var ExtractTextPlugin = require('extract-text-webpack-plugin') |
|||
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') |
|||
|
|||
var env = config.build.env |
|||
|
|||
var webpackConfig = merge(baseWebpackConfig, { |
|||
module: { |
|||
rules: utils.styleLoaders({ |
|||
sourceMap: config.build.productionSourceMap, |
|||
extract: true |
|||
}) |
|||
}, |
|||
devtool: config.build.productionSourceMap ? '#source-map' : false, |
|||
output: { |
|||
path: config.build.assetsRoot, |
|||
filename: utils.assetsPath('js/[name].[chunkhash].js'), |
|||
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') |
|||
}, |
|||
plugins: [ |
|||
// http://vuejs.github.io/vue-loader/en/workflow/production.html
|
|||
new webpack.DefinePlugin({ |
|||
'process.env': env |
|||
}), |
|||
new webpack.optimize.UglifyJsPlugin({ |
|||
compress: { |
|||
warnings: false |
|||
}, |
|||
sourceMap: true |
|||
}), |
|||
// extract css into its own file
|
|||
new ExtractTextPlugin({ |
|||
filename: utils.assetsPath('css/[name].[contenthash].css') |
|||
}), |
|||
// Compress extracted CSS. We are using this plugin so that possible
|
|||
// duplicated CSS from different components can be deduped.
|
|||
new OptimizeCSSPlugin({ |
|||
cssProcessorOptions: { |
|||
safe: true |
|||
} |
|||
}), |
|||
// generate dist index.html with correct asset hash for caching.
|
|||
// you can customize output by editing /index.html
|
|||
// see https://github.com/ampedandwired/html-webpack-plugin
|
|||
new HtmlWebpackPlugin({ |
|||
filename: config.build.index, |
|||
template: 'index.html', |
|||
inject: true, |
|||
minify: { |
|||
removeComments: true, |
|||
collapseWhitespace: true, |
|||
removeAttributeQuotes: true |
|||
// more options:
|
|||
// https://github.com/kangax/html-minifier#options-quick-reference
|
|||
}, |
|||
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
|
|||
chunksSortMode: 'dependency' |
|||
}), |
|||
// split vendor js into its own file
|
|||
new webpack.optimize.CommonsChunkPlugin({ |
|||
name: 'vendor', |
|||
minChunks: function (module, count) { |
|||
// any required modules inside node_modules are extracted to vendor
|
|||
return ( |
|||
module.resource && |
|||
/\.js$/.test(module.resource) && |
|||
module.resource.indexOf( |
|||
path.join(__dirname, '../node_modules') |
|||
) === 0 |
|||
) |
|||
} |
|||
}), |
|||
// extract webpack runtime and module manifest to its own file in order to
|
|||
// prevent vendor hash from being updated whenever app bundle is updated
|
|||
new webpack.optimize.CommonsChunkPlugin({ |
|||
name: 'manifest', |
|||
chunks: ['vendor'] |
|||
}), |
|||
// copy custom static assets
|
|||
new CopyWebpackPlugin([ |
|||
{ |
|||
from: path.resolve(__dirname, '../static'), |
|||
to: config.build.assetsSubDirectory, |
|||
ignore: ['.*'] |
|||
} |
|||
]) |
|||
] |
|||
}) |
|||
|
|||
if (config.build.productionGzip) { |
|||
var CompressionWebpackPlugin = require('compression-webpack-plugin') |
|||
|
|||
webpackConfig.plugins.push( |
|||
new CompressionWebpackPlugin({ |
|||
asset: '[path].gz[query]', |
|||
algorithm: 'gzip', |
|||
test: new RegExp( |
|||
'\\.(' + |
|||
config.build.productionGzipExtensions.join('|') + |
|||
')$' |
|||
), |
|||
threshold: 10240, |
|||
minRatio: 0.8 |
|||
}) |
|||
) |
|||
} |
|||
|
|||
if (config.build.bundleAnalyzerReport) { |
|||
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin |
|||
webpackConfig.plugins.push(new BundleAnalyzerPlugin()) |
|||
} |
|||
|
|||
module.exports = webpackConfig |
@ -0,0 +1,7 @@ |
|||
var merge = require('webpack-merge') |
|||
var prodEnv = require('./prod.env') |
|||
// www.yjlive.cn
|
|||
module.exports = merge(prodEnv, { |
|||
NODE_ENV: '"development"', |
|||
BASE_API: '"http://127.0.0.1:8083"' |
|||
}) |
@ -0,0 +1,54 @@ |
|||
// see http://vuejs-templates.github.io/webpack for documentation.
|
|||
var path = require('path') |
|||
|
|||
module.exports = { |
|||
build: { |
|||
env: require('./prod.env'), |
|||
index: path.resolve(__dirname, '../dist/index.html'), |
|||
assetsRoot: path.resolve(__dirname, '../dist'), |
|||
assetsSubDirectory: 'static', |
|||
assetsPublicPath: './', |
|||
productionSourceMap: true, |
|||
// Gzip off by default as many popular static hosts such as
|
|||
// Surge or Netlify already gzip all static assets for you.
|
|||
// Before setting to `true`, make sure to:
|
|||
// npm install --save-dev compression-webpack-plugin
|
|||
productionGzip: false, |
|||
productionGzipExtensions: ['js', 'css'], |
|||
// Run the build command with an extra argument to
|
|||
// View the bundle analyzer report after build finishes:
|
|||
// `npm run build --report`
|
|||
// Set to `true` or `false` to always turn it on or off
|
|||
bundleAnalyzerReport: process.env.npm_config_report |
|||
}, |
|||
dev: { |
|||
env: require('./dev.env'), |
|||
// Paths
|
|||
assetsSubDirectory: 'static', |
|||
assetsPublicPath: '/', |
|||
proxyTable: {}, |
|||
|
|||
// Various Dev Server settings
|
|||
host: '127.0.0.1', // can be overwritten by process.env.HOST localhost
|
|||
port: 1428, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
|
|||
autoOpenBrowser: false, |
|||
errorOverlay: true, |
|||
notifyOnErrors: true, |
|||
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
|
|||
|
|||
|
|||
/** |
|||
* Source Maps |
|||
*/ |
|||
|
|||
// https://webpack.js.org/configuration/devtool/#development
|
|||
devtool: 'cheap-module-eval-source-map', |
|||
|
|||
// If you have problems debugging vue-files in devtools,
|
|||
// set this to false - it *may* help
|
|||
// https://vue-loader.vuejs.org/en/options.html#cachebusting
|
|||
cacheBusting: true, |
|||
|
|||
cssSourceMap: true |
|||
} |
|||
} |
@ -0,0 +1,4 @@ |
|||
module.exports = { |
|||
NODE_ENV: '"production"', |
|||
BASE_API: '"/portalapi"' |
|||
} |
@ -0,0 +1,122 @@ |
|||
import request from './public' |
|||
// 商品列表
|
|||
export const getAllGoods = (params) => { |
|||
return request.post('/goods.getlist', params) |
|||
} |
|||
// 获取购物车列表
|
|||
export const getCartList = (params) => { |
|||
return request.post('/cart.getlist', params) |
|||
} |
|||
// 加入购物车
|
|||
export const addCart = (params) => { |
|||
return request.post('/cart.add', params) |
|||
} |
|||
// 删除购物车
|
|||
export const delCart = (params) => { |
|||
return request.post('/cart.del', params) |
|||
} |
|||
// 删除购物车勾选商品
|
|||
export const delCartChecked = (params) => { |
|||
return request.post('/api/cart/delCartChecked', params) |
|||
} |
|||
// 编辑购物车
|
|||
export const cartEdit = (params) => { |
|||
return request.post('/api/cart/cartEdit', params) |
|||
} |
|||
// 全选
|
|||
export const editCheckAll = (params) => { |
|||
return request.post('/api/cart/editCheckAll', params) |
|||
} |
|||
// 删除整条购物车
|
|||
export const cartDel = (params) => { |
|||
return request.post('/api/member/cartDel', params) |
|||
} |
|||
// 获取用户地址
|
|||
export const addressList = (params) => { |
|||
return request.post('/user.getusership', params) |
|||
} |
|||
// 通过id获取地址
|
|||
export const getAddress = (params) => { |
|||
return request.post('/user.getshipdetail', params) |
|||
} |
|||
// 设为默认
|
|||
export const addressUpdate = (params) => { |
|||
return request.post('/user.vuesaveusership', params) |
|||
} |
|||
// 添加收货地址
|
|||
export const addressAdd = (params) => { |
|||
return request.post('/user.vuesaveusership', params) |
|||
} |
|||
// 删除收货地址
|
|||
export const addressDel = (params) => { |
|||
return request.post('/user.removeship', params) |
|||
} |
|||
// 预览订单
|
|||
export const submitPreview = (params) => { |
|||
return request.post('/submitPreview', params) |
|||
} |
|||
// 生成订单
|
|||
export const submitOrder = (params) => { |
|||
return request.post('/order.create', params) |
|||
} |
|||
// 支付
|
|||
export const payMent = (params) => { |
|||
return request.post('/api/order/payOrder', params) |
|||
} |
|||
// 获取用户订单
|
|||
export const orderList = (params) => { |
|||
return request.post('/order.getorderlist', params) |
|||
} |
|||
// 获取单个订单详情
|
|||
export const getOrderDet = (params) => { |
|||
return request.post('/order.details', params) |
|||
} |
|||
// 取消订单
|
|||
export const cancelOrder = (params) => { |
|||
return request.post('/order.cancel', params) |
|||
} |
|||
// 商品详情
|
|||
export const productDet = (params) => { |
|||
return request.post('/goods.getdetial', params) |
|||
} |
|||
// 删除订单
|
|||
export const delOrder = (params) => { |
|||
return request.post('/api/member/delOrder', params) |
|||
} |
|||
// 商品列表
|
|||
export const getSearch = (params) => { |
|||
return request.post('/goods.getlist', params) |
|||
} |
|||
// 快速搜索
|
|||
export const getQuickSearch = (params) => { |
|||
return request.post('/goods.getlist', params) |
|||
} |
|||
|
|||
/** |
|||
* 生成支付二维码(模式一)并在页面上显示 |
|||
*/ |
|||
export const scanCode = (params) => { |
|||
return request.post('/api/wxpay/scanCode1', params) |
|||
} |
|||
/** |
|||
* 扫码支付模式二 |
|||
* 已测试 |
|||
*/ |
|||
export const scanCode2 = (params) => { |
|||
return request.post('/api/wxpay/scanCode2', params) |
|||
} |
|||
|
|||
/** |
|||
* 扫码支付模式一回调 |
|||
* 已测试 |
|||
*/ |
|||
export const wxpay = (params) => { |
|||
return request.post('/api/wxpay/wxpay', params) |
|||
} |
|||
/** |
|||
* 刷卡支付 |
|||
* 已测试 |
|||
*/ |
|||
export const micropay = (params) => { |
|||
return request.post('/api/wxpay/micropay', params) |
|||
} |
@ -0,0 +1,50 @@ |
|||
import request from './public' |
|||
// 登陆
|
|||
export const userLogin = (params) => { |
|||
return request.post('/user.login', params) |
|||
} |
|||
// 退出登陆
|
|||
export const loginOut = (params) => { |
|||
return request.post('/user.logout', params) |
|||
} |
|||
// 用户信息
|
|||
export const userInfo = (params) => { |
|||
return request.post('/user.info', params) |
|||
} |
|||
// 注册账号
|
|||
export const register = (params) => { |
|||
return request.post('/user.reg', params) |
|||
} |
|||
// 上传图片
|
|||
export const upload = (params) => { |
|||
return request.post('/upload', params) |
|||
} |
|||
// 修改头像
|
|||
export const updateheadimage = (params) => { |
|||
return request.post('/user.editinfo', params) |
|||
} |
|||
// 捐赠列表
|
|||
export const thanksList = (params) => { |
|||
return request.post('/api/member/thanks', params) |
|||
} |
|||
// 首页接口
|
|||
export const productHome = (params) => { |
|||
return request.post('/pc.getpageconfig', params) |
|||
} |
|||
// 首页接口
|
|||
export const navList = (params) => { |
|||
return request.post('/home.navlist', params) |
|||
} |
|||
// 推荐板块
|
|||
export const recommend = (params) => { |
|||
return request.post('/hotProductList/list', params) |
|||
} |
|||
// 捐赠板块
|
|||
export const thank = (params) => { |
|||
return request.post('/api/goods/thank', params) |
|||
} |
|||
// 极验验证码
|
|||
export const geetest = (params) => { |
|||
return request.post('/api/member/geetestInit?t=' + (new Date()).getTime(), params) |
|||
} |
|||
|
@ -0,0 +1,178 @@ |
|||
import axios from 'axios' |
|||
import Qs from "qs"; |
|||
import { getStore } from '/utils/storage' |
|||
import toLogin from './login' |
|||
const instance = axios.create({ |
|||
transformRequest: [ |
|||
function(data) { |
|||
data = Qs.stringify(data); |
|||
return data; |
|||
} |
|||
], |
|||
// www.yjlive.cn
|
|||
baseURL: "http://127.0.0.1:8083/", |
|||
timeout: 30000 |
|||
}); |
|||
instance.defaults.headers.post["Content-Type"] = |
|||
"application/x-www-form-urlencoded"; |
|||
const defaultOpt = { login: true }; |
|||
const methodsToken = [ |
|||
"user.info", |
|||
"user.editinfo", |
|||
"user.changeavatar", |
|||
"user.logout", |
|||
"user.addgoodsbrowsing", |
|||
"user.delgoodsbrowsing", |
|||
"user.goodsbrowsing", |
|||
"user.goodscollection", |
|||
"user.goodscollectionlist", |
|||
"user.vuesaveusership", |
|||
"user.saveusership", |
|||
"user.getshipdetail", |
|||
"user.setdefship", |
|||
"user.editship", |
|||
"user.removeship", |
|||
"user.getusership", |
|||
"api/wxpay/user.pay", |
|||
"user.orderevaluate", |
|||
"user.getuserdefaultship", |
|||
"user.issign", |
|||
"user.sign", |
|||
"user.mypoint", |
|||
"user.userpointlog", |
|||
"user.getbankcardlist", |
|||
"user.getdefaultbankcard", |
|||
"user.addbankcard", |
|||
"user.removebankcard", |
|||
"user.setdefaultbankcard", |
|||
"user.getbankcardinfo", |
|||
"user.editpwd", |
|||
"user.forgotpwd", |
|||
"user.recommend", |
|||
"user.balancelist", |
|||
"user.sharecode", |
|||
"user.cash", |
|||
"user.cashlist", |
|||
"user.myinvite", |
|||
"user.activationinvite", |
|||
"coupon.getcoupon", |
|||
"coupon.usercoupon", |
|||
"cart.add", |
|||
"cart.del", |
|||
"cart.getlist", |
|||
"cart.setnums", |
|||
"cart.getnumber", |
|||
"order.cancel", |
|||
"order.del", |
|||
"order.details", |
|||
"order.confirm", |
|||
"order.getlist", |
|||
"order.create", |
|||
"submitPreview", |
|||
"order.getship", |
|||
"order.getorderlist", |
|||
"order.getorderstatusnum", |
|||
"order.aftersaleslist", |
|||
"order.aftersalesinfo", |
|||
"order.aftersalesstatus", |
|||
"order.addaftersales", |
|||
"order.sendreship", |
|||
"order.iscomment", |
|||
"payments.getinfo", |
|||
"user.getuserpoint", |
|||
"coupon.getcouponkey", |
|||
"store.isclerk", |
|||
"store.storeladinglist", |
|||
"store.ladinginfo", |
|||
"store.lading", |
|||
"store.ladingdel", |
|||
"distribution_center-api-info", |
|||
"distribution_center-api-applydistribution", |
|||
"distribution_center-api-setstore", |
|||
"distribution_center-api-myorder", |
|||
"pintuan.pintuanteam", |
|||
"lottery-api-getLotteryConfig", |
|||
"lottery-api-lottery", |
|||
"lottery-api-lotteryLog" |
|||
]; |
|||
|
|||
function baseRequest(options) { |
|||
const token = getStore('token'); |
|||
const headers = options.headers || {}; |
|||
|
|||
headers["Accept"] = "application/json"; |
|||
headers["Content-Type"] = "application/x-www-form-urlencoded"; |
|||
headers["authorization"] = token; |
|||
headers["storeid"] = 2; |
|||
options.headers = headers; |
|||
if (options.login && !token) { |
|||
// toLogin();
|
|||
// return Promise.reject({ msg: "未登录", toLogin: true });
|
|||
} |
|||
console.log(options); |
|||
var url = options.url.substring(1, options.url.length); |
|||
// 判断token是否存在
|
|||
if (methodsToken.indexOf(url) >= 0) { |
|||
if (!token) { |
|||
// this.$router.push({path: '/page/Login/login'})
|
|||
toLogin(); |
|||
return Promise.reject({ msg: "未登录", toLogin: true }); |
|||
} else { |
|||
//data.authorization = userToken;
|
|||
} |
|||
} |
|||
|
|||
return instance(options).then(res => { |
|||
const data = res.data || {}; |
|||
if (res.status !== 200) |
|||
return Promise.reject({ msg: "请求失败", res, data }); |
|||
|
|||
if ([410000, 410001, 410002, 100].indexOf(data.status) !== -1) { |
|||
// this.$router.push({path: '/page/Login/login'})
|
|||
toLogin(); |
|||
return Promise.reject({ msg: res.data.msg, res, data, toLogin: true }); |
|||
} else if (data.code === 200) { |
|||
return Promise.resolve(data, res); |
|||
} else { |
|||
return Promise.reject({ msg: res.data.msg, res, data }); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* http 请求基础类 |
|||
* 参考文档 https://www.kancloud.cn/yunye/axios/234845
|
|||
* |
|||
*/ |
|||
const request = ["post", "put", "patch"].reduce((request, method) => { |
|||
/** |
|||
* |
|||
* @param url string 接口地址 |
|||
* @param data object get参数 |
|||
* @param options object axios 配置项 |
|||
* @returns {AxiosPromise} |
|||
*/ |
|||
request[method] = (url, data, options = {}) => { |
|||
return baseRequest( |
|||
Object.assign({ url, data, method }, defaultOpt, options) |
|||
); |
|||
}; |
|||
return request; |
|||
}, {}); |
|||
|
|||
["get", "delete", "head"].forEach(method => { |
|||
/** |
|||
* |
|||
* @param url string 接口地址 |
|||
* @param params object get参数 |
|||
* @param options object axios 配置项 |
|||
* @returns {AxiosPromise} |
|||
*/ |
|||
request[method] = (url, params = {}, options = {}) => { |
|||
return baseRequest( |
|||
Object.assign({ url, params, method }, defaultOpt, options) |
|||
); |
|||
}; |
|||
}); |
|||
|
|||
export default request; |
@ -0,0 +1,179 @@ |
|||
import axios from 'axios' |
|||
import Qs from "qs"; |
|||
import { getStore } from '/utils/storage' |
|||
import toLogin from './login' |
|||
const instance = axios.create({ |
|||
transformRequest: [ |
|||
function(data) { |
|||
data = Qs.stringify(data); |
|||
return data; |
|||
} |
|||
], |
|||
// www.yjlive.cn
|
|||
baseURL: "http://mall.yyundong.com/portalapi/", |
|||
// baseURL: "http://www.yyundong.com:8083/",
|
|||
timeout: 30000 |
|||
}); |
|||
instance.defaults.headers.post["Content-Type"] = |
|||
"application/x-www-form-urlencoded"; |
|||
const defaultOpt = { login: true }; |
|||
const methodsToken = [ |
|||
"user.info", |
|||
"user.editinfo", |
|||
"user.changeavatar", |
|||
"user.logout", |
|||
"user.addgoodsbrowsing", |
|||
"user.delgoodsbrowsing", |
|||
"user.goodsbrowsing", |
|||
"user.goodscollection", |
|||
"user.goodscollectionlist", |
|||
"user.vuesaveusership", |
|||
"user.saveusership", |
|||
"user.getshipdetail", |
|||
"user.setdefship", |
|||
"user.editship", |
|||
"user.removeship", |
|||
"user.getusership", |
|||
"api/wxpay/user.pay", |
|||
"user.orderevaluate", |
|||
"user.getuserdefaultship", |
|||
"user.issign", |
|||
"user.sign", |
|||
"user.mypoint", |
|||
"user.userpointlog", |
|||
"user.getbankcardlist", |
|||
"user.getdefaultbankcard", |
|||
"user.addbankcard", |
|||
"user.removebankcard", |
|||
"user.setdefaultbankcard", |
|||
"user.getbankcardinfo", |
|||
"user.editpwd", |
|||
"user.forgotpwd", |
|||
"user.recommend", |
|||
"user.balancelist", |
|||
"user.sharecode", |
|||
"user.cash", |
|||
"user.cashlist", |
|||
"user.myinvite", |
|||
"user.activationinvite", |
|||
"coupon.getcoupon", |
|||
"coupon.usercoupon", |
|||
"cart.add", |
|||
"cart.del", |
|||
"cart.getlist", |
|||
"cart.setnums", |
|||
"cart.getnumber", |
|||
"order.cancel", |
|||
"order.del", |
|||
"order.details", |
|||
"order.confirm", |
|||
"order.getlist", |
|||
"order.create", |
|||
"submitPreview", |
|||
"order.getship", |
|||
"order.getorderlist", |
|||
"order.getorderstatusnum", |
|||
"order.aftersaleslist", |
|||
"order.aftersalesinfo", |
|||
"order.aftersalesstatus", |
|||
"order.addaftersales", |
|||
"order.sendreship", |
|||
"order.iscomment", |
|||
"payments.getinfo", |
|||
"user.getuserpoint", |
|||
"coupon.getcouponkey", |
|||
"store.isclerk", |
|||
"store.storeladinglist", |
|||
"store.ladinginfo", |
|||
"store.lading", |
|||
"store.ladingdel", |
|||
"distribution_center-api-info", |
|||
"distribution_center-api-applydistribution", |
|||
"distribution_center-api-setstore", |
|||
"distribution_center-api-myorder", |
|||
"pintuan.pintuanteam", |
|||
"lottery-api-getLotteryConfig", |
|||
"lottery-api-lottery", |
|||
"lottery-api-lotteryLog" |
|||
]; |
|||
|
|||
function baseRequest(options) { |
|||
const token = getStore('token'); |
|||
const headers = options.headers || {}; |
|||
|
|||
headers["Accept"] = "application/json"; |
|||
headers["Content-Type"] = "application/x-www-form-urlencoded"; |
|||
headers["authorization"] = token; |
|||
headers["storeid"] = 2; |
|||
options.headers = headers; |
|||
if (options.login && !token) { |
|||
// toLogin();
|
|||
// return Promise.reject({ msg: "未登录", toLogin: true });
|
|||
} |
|||
console.log(options); |
|||
var url = options.url.substring(1, options.url.length); |
|||
// 判断token是否存在
|
|||
if (methodsToken.indexOf(url) >= 0) { |
|||
if (!token) { |
|||
// this.$router.push({path: '/page/Login/login'})
|
|||
toLogin(); |
|||
return Promise.reject({ msg: "未登录", toLogin: true }); |
|||
} else { |
|||
//data.authorization = userToken;
|
|||
} |
|||
} |
|||
|
|||
return instance(options).then(res => { |
|||
const data = res.data || {}; |
|||
if (res.status !== 200) |
|||
return Promise.reject({ msg: "请求失败", res, data }); |
|||
|
|||
if ([410000, 410001, 410002, 100].indexOf(data.status) !== -1) { |
|||
// this.$router.push({path: '/page/Login/login'})
|
|||
toLogin(); |
|||
return Promise.reject({ msg: res.data.msg, res, data, toLogin: true }); |
|||
} else if (data.code === 200) { |
|||
return Promise.resolve(data, res); |
|||
} else { |
|||
return Promise.reject({ msg: res.data.msg, res, data }); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* http 请求基础类 |
|||
* 参考文档 https://www.kancloud.cn/yunye/axios/234845
|
|||
* |
|||
*/ |
|||
const request = ["post", "put", "patch"].reduce((request, method) => { |
|||
/** |
|||
* |
|||
* @param url string 接口地址 |
|||
* @param data object get参数 |
|||
* @param options object axios 配置项 |
|||
* @returns {AxiosPromise} |
|||
*/ |
|||
request[method] = (url, data, options = {}) => { |
|||
return baseRequest( |
|||
Object.assign({ url, data, method }, defaultOpt, options) |
|||
); |
|||
}; |
|||
return request; |
|||
}, {}); |
|||
|
|||
["get", "delete", "head"].forEach(method => { |
|||
/** |
|||
* |
|||
* @param url string 接口地址 |
|||
* @param params object get参数 |
|||
* @param options object axios 配置项 |
|||
* @returns {AxiosPromise} |
|||
*/ |
|||
request[method] = (url, params = {}, options = {}) => { |
|||
return baseRequest( |
|||
Object.assign({ url, params, method }, defaultOpt, options) |
|||
); |
|||
}; |
|||
}); |
|||
|
|||
export default request; |
@ -0,0 +1,48 @@ |
|||
import Vue from 'vue' |
|||
import App from './App' |
|||
import router from './router' |
|||
import store from './store/' |
|||
import VueLazyload from 'vue-lazyload' |
|||
import infiniteScroll from 'vue-infinite-scroll' |
|||
import VueCookie from 'vue-cookie' |
|||
import { userInfo } from './api' |
|||
import { Button, Pagination, Checkbox, Icon, Autocomplete, Loading, Message, Notification, Steps, Step, Table, TableColumn, Input, Dialog, Select, Option } from 'element-ui' |
|||
import { getStore } from '/utils/storage' |
|||
import VueContentPlaceholders from 'vue-content-placeholders' |
|||
Vue.use(VueContentPlaceholders) |
|||
Vue.use(Button) |
|||
Vue.use(Pagination) |
|||
Vue.use(Checkbox) |
|||
Vue.use(Icon) |
|||
Vue.use(Autocomplete) |
|||
Vue.use(Steps) |
|||
Vue.use(Step) |
|||
Vue.use(Table) |
|||
Vue.use(TableColumn) |
|||
Vue.use(Input) |
|||
Vue.use(Dialog) |
|||
Vue.use(Select) |
|||
Vue.use(Option) |
|||
Vue.use(Loading.directive) |
|||
Vue.prototype.$loading = Loading.service |
|||
Vue.prototype.$notify = Notification |
|||
Vue.prototype.$message = Message |
|||
Vue.use(infiniteScroll) |
|||
Vue.use(VueCookie) |
|||
Vue.use(VueLazyload, { |
|||
// preLoad: 1.3,
|
|||
// error: 'dist/error.png',
|
|||
loading: '/static/images/load.gif' |
|||
// attempt: 1
|
|||
}) |
|||
Vue.config.productionTip = false |
|||
const whiteList = ['/home', '/goods', '/login', '/register', '/goodsDetails', '/thanks', '/search', '/refreshsearch', |
|||
'/refreshgoods'] // 不需要登陆的页面
|
|||
|
|||
/* eslint-disable no-new */ |
|||
new Vue({ |
|||
el: '#app', |
|||
store, |
|||
router, |
|||
render: h => h(App) |
|||
}) |
@ -0,0 +1,80 @@ |
|||
import Vue from 'vue' |
|||
import Router from 'vue-router' |
|||
const Index = () => import('/page/index.vue') |
|||
const Login = () => import('/page/Login/login.vue') |
|||
const Register = () => import('/page/Login/register.vue') |
|||
const Home = () => import('/page/Home/home.vue') |
|||
const GoodS = () => import('/page/Goods/goods.vue') |
|||
const goodsDetails = () => import('/page/Goods/goodsDetails.vue') |
|||
const Cart = () => import('/page/Cart/cart.vue') |
|||
const order = () => import('/page/Order/order.vue') |
|||
const user = () => import('/page/User/user.vue') |
|||
const orderList = () => import('/page/User/children/order.vue') |
|||
const information = () => import('/page/User/children/information.vue') |
|||
const addressList = () => import('/page/User/children/addressList.vue') |
|||
const coupon = () => import('/page/User/children/coupon.vue') |
|||
const aihuishou = () => import('/page/User/children/aihuishou.vue') |
|||
const support = () => import('/page/User/children/support.vue') |
|||
const checkout = () => import('/page/Checkout/checkout.vue') |
|||
const payment = () => import('/page/Order/payment.vue') |
|||
const paysuccess = () => import('/page/Order/paysuccess.vue') |
|||
const Thanks = () => import('/page/Thanks/thanks.vue') |
|||
const Search = () => import('/page/Search/search.vue') |
|||
const RefreshSearch = () => import('/page/Refresh/refreshsearch.vue') |
|||
const RefreshGoods = () => import('/page/Refresh/refreshgoods.vue') |
|||
const orderDetail = () => import('/page/User/children/orderDetail.vue') |
|||
const Alipay = () => import('/page/Order/alipay.vue') |
|||
const Wechat = () => import('/page/Order/wechat.vue') |
|||
const QQpay = () => import('/page/Order/qqpay.vue') |
|||
Vue.use(Router) |
|||
export default new Router({ |
|||
routes: [ |
|||
{ |
|||
path: '/', |
|||
component: Index, |
|||
name: 'index', |
|||
redirect: '/home', |
|||
children: [ |
|||
{path: 'home', component: Home}, |
|||
{path: 'goods', component: GoodS}, |
|||
{path: 'goodsDetails', name: 'goodsDetails', component: goodsDetails}, |
|||
{path: 'thanks', name: 'thanks', component: Thanks}, |
|||
{path: '/refreshgoods', name: 'refreshgoods', component: RefreshGoods} |
|||
] |
|||
}, |
|||
{path: '/login', name: 'login', component: Login}, |
|||
{path: '/register', name: 'register', component: Register}, |
|||
{path: '/cart', name: 'cart', component: Cart}, |
|||
{path: '/refreshsearch', name: 'refreshsearch', component: RefreshSearch}, |
|||
{ |
|||
path: '/order', |
|||
name: 'order', |
|||
component: order, |
|||
children: [ |
|||
{path: 'paysuccess', name: 'paysuccess', component: paysuccess}, |
|||
{path: 'payment', name: 'payment', component: payment}, |
|||
{path: '/search', name: 'search', component: Search}, |
|||
{path: 'alipay', name: 'alipay', component: Alipay}, |
|||
{path: 'wechat', name: 'wechat', component: Wechat}, |
|||
{path: 'qqpay', name: 'qqpay', component: QQpay} |
|||
] |
|||
}, |
|||
{ |
|||
path: '/user', |
|||
name: 'user', |
|||
component: user, |
|||
redirect: '/user/orderList', |
|||
children: [ |
|||
{path: 'orderList', name: '订单列表', component: orderList}, |
|||
{path: 'orderDetail', name: '订单详情', component: orderDetail}, |
|||
{path: 'information', name: '账户资料', component: information}, |
|||
{path: 'addressList', name: '收货地址', component: addressList}, |
|||
{path: 'coupon', name: '我的优惠', component: coupon}, |
|||
{path: 'support', name: '售后服务', component: support}, |
|||
{path: 'aihuishou', name: '以旧换新', component: aihuishou} |
|||
] |
|||
}, |
|||
{path: '/checkout', name: 'checkout', component: checkout}, |
|||
{path: '*', redirect: '/home'} |
|||
] |
|||
}) |
@ -0,0 +1 @@ |
|||
export default {} |
@ -0,0 +1,25 @@ |
|||
import Vue from 'vue' |
|||
import Vuex from 'vuex' |
|||
import mutations from './mutations' |
|||
import action from './action' |
|||
Vue.use(Vuex) |
|||
|
|||
const state = { |
|||
login: false, // 是否登录
|
|||
userInfo: null, // 用户信息
|
|||
cartList: [], // 加入购物车列表
|
|||
showMoveImg: false, // 显示飞入图片
|
|||
elLeft: 0, |
|||
elTop: 0, |
|||
moveImgUrl: null, |
|||
cartPositionT: 0, // 购物车位置
|
|||
cartPositionL: 0, |
|||
receiveInCart: false, // 是否进入购物车
|
|||
showCart: false // 是否显示购物车
|
|||
} |
|||
|
|||
export default new Vuex.Store({ |
|||
state, |
|||
action, |
|||
mutations |
|||
}) |
@ -0,0 +1,8 @@ |
|||
export const INIT_BUYCART = 'INIT_BUYCART' |
|||
export const ADD_CART = 'ADD_CART' |
|||
export const GET_USERINFO = 'GET_USERINFO' |
|||
export const RECORD_USERINFO = 'RECORD_USERINFO' |
|||
export const ADD_ANIMATION = 'ADD_ANIMATION' |
|||
export const SHOW_CART = 'SHOW_CART' |
|||
export const REDUCE_CART = 'REDUCE_CART' |
|||
export const EDIT_CART = 'EDIT_CART' |
@ -0,0 +1,135 @@ |
|||
import { |
|||
INIT_BUYCART, |
|||
ADD_CART, |
|||
GET_USERINFO, |
|||
RECORD_USERINFO, |
|||
ADD_ANIMATION, |
|||
SHOW_CART, |
|||
REDUCE_CART, |
|||
EDIT_CART |
|||
} from './mutation-types' |
|||
import { setStore, getStore } from '../utils/storage' |
|||
export default { |
|||
// 网页初始化时从本地缓存获取购物车数据
|
|||
[INIT_BUYCART] (state) { |
|||
let initCart = getStore('buyCart') |
|||
if (initCart) { |
|||
state.cartList = JSON.parse(initCart) |
|||
} |
|||
}, |
|||
// 加入购物车
|
|||
[ADD_CART] (state, {productId, salePrice, productName, productImg, productNum = 1}) { |
|||
let cart = state.cartList // 购物车
|
|||
let falg = true |
|||
let goods = { |
|||
productId, |
|||
salePrice, |
|||
productName, |
|||
productImg |
|||
} |
|||
if (cart.length) { // 有内容
|
|||
cart.forEach(item => { |
|||
if (item.productId === productId) { |
|||
if (item.productNum >= 0) { |
|||
falg = false |
|||
item.productNum += productNum |
|||
} |
|||
} |
|||
}) |
|||
} |
|||
if (!cart.length || falg) { |
|||
goods.productNum = productNum |
|||
goods.checked = '1' |
|||
cart.push(goods) |
|||
} |
|||
state.cartList = cart |
|||
// 存入localStorage
|
|||
setStore('buyCart', cart) |
|||
}, |
|||
// 加入购物车动画
|
|||
[ADD_ANIMATION] (state, {moveShow, elLeft, elTop, img, cartPositionT, cartPositionL, receiveInCart}) { |
|||
state.showMoveImg = moveShow |
|||
if (elLeft) { |
|||
state.elLeft = elLeft |
|||
state.elTop = elTop |
|||
} |
|||
state.moveImgUrl = img |
|||
state.receiveInCart = receiveInCart |
|||
if (cartPositionT) { |
|||
state.cartPositionT = cartPositionT |
|||
state.cartPositionL = cartPositionL |
|||
} |
|||
}, |
|||
// 是否显示购物车
|
|||
[SHOW_CART] (state, {showCart}) { |
|||
// let timer = null
|
|||
state.showCart = showCart |
|||
// clearTimeout(timer)
|
|||
// if (showCart) {
|
|||
// timer = setTimeout(() => {
|
|||
// state.showCart = false
|
|||
// }, 5000)
|
|||
// }
|
|||
}, |
|||
// 移除商品
|
|||
[REDUCE_CART] (state, {productId}) { |
|||
let cart = state.cartList |
|||
cart.forEach((item, i) => { |
|||
if (item.productId === productId) { |
|||
if (item.productNum > 1) { |
|||
item.productNum-- |
|||
} else { |
|||
cart.splice(i, 1) |
|||
} |
|||
} |
|||
}) |
|||
state.cartList = cart |
|||
// 存入localStorage
|
|||
setStore('buyCart', state.cartList) |
|||
}, |
|||
// 修改购物车
|
|||
[EDIT_CART] (state, {productId, productNum, checked}) { |
|||
let cart = state.cartList |
|||
if (productNum) { |
|||
cart.forEach((item, i) => { |
|||
if (item.productId === productId) { |
|||
item.productNum = productNum |
|||
item.checked = checked |
|||
} |
|||
}) |
|||
} else if (productId) { |
|||
cart.forEach((item, i) => { |
|||
if (item.productId === productId) { |
|||
cart.splice(i, 1) |
|||
} |
|||
}) |
|||
} else { |
|||
cart.forEach((item) => { |
|||
item.checked = checked ? '1' : '0' |
|||
}) |
|||
} |
|||
state.cartList = cart |
|||
// 存入localStorage
|
|||
setStore('buyCart', state.cartList) |
|||
}, |
|||
// 记录用户信息
|
|||
[RECORD_USERINFO] (state, info) { |
|||
state.userInfo = info |
|||
state.login = true |
|||
setStore('userInfo', info) |
|||
}, |
|||
// 获取用户信息
|
|||
[GET_USERINFO] (state, info) { |
|||
if (state.userInfo && (state.userInfo.username !== info.username)) { |
|||
return |
|||
} |
|||
if (!state.login) { |
|||
return |
|||
} |
|||
if (!info.message) { |
|||
state.userInfo = {...info} |
|||
} else { |
|||
state.userInfo = null |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,26 @@ |
|||
/** |
|||
* 存储localStorage |
|||
*/ |
|||
export const setStore = (name, content) => { |
|||
if (!name) return |
|||
if (typeof content !== 'string') { |
|||
content = JSON.stringify(content) |
|||
} |
|||
window.localStorage.setItem(name, content) |
|||
} |
|||
|
|||
/** |
|||
* 获取localStorage |
|||
*/ |
|||
export const getStore = name => { |
|||
if (!name) return |
|||
return window.localStorage.getItem(name) |
|||
} |
|||
|
|||
/** |
|||
* 删除localStorage |
|||
*/ |
|||
export const removeStore = name => { |
|||
if (!name) return |
|||
window.localStorage.removeItem(name) |
|||
} |
@ -0,0 +1,276 @@ |
|||
/* initGeetest 1.0.0 |
|||
* 用于加载id对应的验证码库,并支持宕机模式 |
|||
* 暴露 initGeetest 进行验证码的初始化 |
|||
* 一般不需要用户进行修改 |
|||
*/ |
|||
(function (global, factory) { |
|||
"use strict"; |
|||
if (typeof module === "object" && typeof module.exports === "object") { |
|||
// CommonJS
|
|||
module.exports = global.document ? |
|||
factory(global, true) : |
|||
function (w) { |
|||
if (!w.document) { |
|||
throw new Error("Geetest requires a window with a document"); |
|||
} |
|||
return factory(w); |
|||
}; |
|||
} else { |
|||
factory(global); |
|||
} |
|||
})(typeof window !== "undefined" ? window : this, function (window, noGlobal) { |
|||
"use strict"; |
|||
if (typeof window === 'undefined') { |
|||
throw new Error('Geetest requires browser environment'); |
|||
} |
|||
var document = window.document; |
|||
var Math = window.Math; |
|||
var head = document.getElementsByTagName("head")[0]; |
|||
|
|||
function _Object(obj) { |
|||
this._obj = obj; |
|||
} |
|||
|
|||
_Object.prototype = { |
|||
_each: function (process) { |
|||
var _obj = this._obj; |
|||
for (var k in _obj) { |
|||
if (_obj.hasOwnProperty(k)) { |
|||
process(k, _obj[k]); |
|||
} |
|||
} |
|||
return this; |
|||
} |
|||
}; |
|||
function Config(config) { |
|||
var self = this; |
|||
new _Object(config)._each(function (key, value) { |
|||
self[key] = value; |
|||
}); |
|||
} |
|||
|
|||
Config.prototype = { |
|||
api_server: 'api.geetest.com', |
|||
protocol: 'http://', |
|||
type_path: '/gettype.php', |
|||
fallback_config: { |
|||
slide: { |
|||
static_servers: ["static.geetest.com", "dn-staticdown.qbox.me"], |
|||
type: 'slide', |
|||
slide: '/static/js/geetest.0.0.0.js' |
|||
}, |
|||
fullpage: { |
|||
static_servers: ["static.geetest.com", "dn-staticdown.qbox.me"], |
|||
type: 'fullpage', |
|||
fullpage: '/static/js/fullpage.0.0.0.js' |
|||
} |
|||
}, |
|||
_get_fallback_config: function () { |
|||
var self = this; |
|||
if (isString(self.type)) { |
|||
return self.fallback_config[self.type]; |
|||
} else if (self.new_captcha) { |
|||
return self.fallback_config.fullpage; |
|||
} else { |
|||
return self.fallback_config.slide; |
|||
} |
|||
}, |
|||
_extend: function (obj) { |
|||
var self = this; |
|||
new _Object(obj)._each(function (key, value) { |
|||
self[key] = value; |
|||
}) |
|||
} |
|||
}; |
|||
var isNumber = function (value) { |
|||
return (typeof value === 'number'); |
|||
}; |
|||
var isString = function (value) { |
|||
return (typeof value === 'string'); |
|||
}; |
|||
var isBoolean = function (value) { |
|||
return (typeof value === 'boolean'); |
|||
}; |
|||
var isObject = function (value) { |
|||
return (typeof value === 'object' && value !== null); |
|||
}; |
|||
var isFunction = function (value) { |
|||
return (typeof value === 'function'); |
|||
}; |
|||
var callbacks = {}; |
|||
var status = {}; |
|||
var random = function () { |
|||
return parseInt(Math.random() * 10000) + (new Date()).valueOf(); |
|||
}; |
|||
var loadScript = function (url, cb) { |
|||
var script = document.createElement("script"); |
|||
script.charset = "UTF-8"; |
|||
script.async = true; |
|||
script.onerror = function () { |
|||
cb(true); |
|||
}; |
|||
var loaded = false; |
|||
script.onload = script.onreadystatechange = function () { |
|||
if (!loaded && |
|||
(!script.readyState || |
|||
"loaded" === script.readyState || |
|||
"complete" === script.readyState)) { |
|||
|
|||
loaded = true; |
|||
setTimeout(function () { |
|||
cb(false); |
|||
}, 0); |
|||
} |
|||
}; |
|||
script.src = url; |
|||
head.appendChild(script); |
|||
}; |
|||
var normalizeDomain = function (domain) { |
|||
return domain.replace(/^https?:\/\/|\/$/g, ''); |
|||
}; |
|||
var normalizePath = function (path) { |
|||
path = path.replace(/\/+/g, '/'); |
|||
if (path.indexOf('/') !== 0) { |
|||
path = '/' + path; |
|||
} |
|||
return path; |
|||
}; |
|||
var normalizeQuery = function (query) { |
|||
if (!query) { |
|||
return ''; |
|||
} |
|||
var q = '?'; |
|||
new _Object(query)._each(function (key, value) { |
|||
if (isString(value) || isNumber(value) || isBoolean(value)) { |
|||
q = q + encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&'; |
|||
} |
|||
}); |
|||
if (q === '?') { |
|||
q = ''; |
|||
} |
|||
return q.replace(/&$/, ''); |
|||
}; |
|||
var makeURL = function (protocol, domain, path, query) { |
|||
domain = normalizeDomain(domain); |
|||
|
|||
var url = normalizePath(path) + normalizeQuery(query); |
|||
if (domain) { |
|||
url = protocol + domain + url; |
|||
} |
|||
|
|||
return url; |
|||
}; |
|||
var load = function (protocol, domains, path, query, cb) { |
|||
var tryRequest = function (at) { |
|||
|
|||
var url = makeURL(protocol, domains[at], path, query); |
|||
loadScript(url, function (err) { |
|||
if (err) { |
|||
if (at >= domains.length - 1) { |
|||
cb(true); |
|||
} else { |
|||
tryRequest(at + 1); |
|||
} |
|||
} else { |
|||
cb(false); |
|||
} |
|||
}); |
|||
}; |
|||
tryRequest(0); |
|||
}; |
|||
var jsonp = function (domains, path, config, callback) { |
|||
if (isObject(config.getLib)) { |
|||
config._extend(config.getLib); |
|||
callback(config); |
|||
return; |
|||
} |
|||
if (config.offline) { |
|||
callback(config._get_fallback_config()); |
|||
return; |
|||
} |
|||
var cb = "geetest_" + random(); |
|||
window[cb] = function (data) { |
|||
if (data.status === 'success') { |
|||
callback(data.data); |
|||
} else if (!data.status) { |
|||
callback(data); |
|||
} else { |
|||
callback(config._get_fallback_config()); |
|||
} |
|||
window[cb] = undefined; |
|||
try { |
|||
delete window[cb]; |
|||
} catch (e) { |
|||
} |
|||
}; |
|||
load(config.protocol, domains, path, { |
|||
gt: config.gt, |
|||
callback: cb |
|||
}, function (err) { |
|||
if (err) { |
|||
callback(config._get_fallback_config()); |
|||
} |
|||
}); |
|||
}; |
|||
var throwError = function (errorType, config) { |
|||
var errors = { |
|||
networkError: '网络错误' |
|||
}; |
|||
if (typeof config.onError === 'function') { |
|||
config.onError(errors[errorType]); |
|||
} else { |
|||
throw new Error(errors[errorType]); |
|||
} |
|||
}; |
|||
var detect = function () { |
|||
return !!window.Geetest; |
|||
}; |
|||
if (detect()) { |
|||
status.slide = "loaded"; |
|||
} |
|||
var initGeetest = function (userConfig, callback) { |
|||
var config = new Config(userConfig); |
|||
if (userConfig.https) { |
|||
config.protocol = 'https://'; |
|||
} else if (!userConfig.protocol) { |
|||
config.protocol = window.location.protocol + '//'; |
|||
} |
|||
jsonp([config.api_server || config.apiserver], config.type_path, config, function (newConfig) { |
|||
var type = newConfig.type; |
|||
var init = function () { |
|||
config._extend(newConfig); |
|||
callback(new window.Geetest(config)); |
|||
}; |
|||
callbacks[type] = callbacks[type] || []; |
|||
var s = status[type] || 'init'; |
|||
if (s === 'init') { |
|||
status[type] = 'loading'; |
|||
callbacks[type].push(init); |
|||
load(config.protocol, newConfig.static_servers || newConfig.domains, newConfig[type] || newConfig.path, null, function (err) { |
|||
if (err) { |
|||
status[type] = 'fail'; |
|||
throwError('networkError', config); |
|||
} else { |
|||
status[type] = 'loaded'; |
|||
var cbs = callbacks[type]; |
|||
for (var i = 0, len = cbs.length; i < len; i = i + 1) { |
|||
var cb = cbs[i]; |
|||
if (isFunction(cb)) { |
|||
cb(); |
|||
} |
|||
} |
|||
callbacks[type] = []; |
|||
} |
|||
}); |
|||
} else if (s === "loaded") { |
|||
init(); |
|||
} else if (s === "fail") { |
|||
throwError('networkError', config); |
|||
} else if (s === "loading") { |
|||
callbacks[type].push(init); |
|||
} |
|||
}); |
|||
}; |
|||
window.initGeetest = initGeetest; |
|||
return initGeetest; |
|||
}); |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue