Commit 844b0d17 by YoMon

首次提交

parents
module.exports = {
root: true,
parser: 'babel-eslint',
env: {
browser: true,
node: true
},
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
rules: {
'space-before-function-paren': [
2,
{
anonymous: 'always',
named: 'never'
}
],
},
globals: {}
}
/node_modules
/.nuxt
/build
/.editorconfig
/.git-credentials
/wlog.log
/session.log
/package-lock.json
from node:8.11.3-alpine
VOLUME /home/app
COPY .nuxt /home/app/.nuxt
COPY assets /home/app/assets
COPY static /home/app/static
COPY build /home/app/build
COPY node_modules /home/app/node_modules
COPY package.json /home/app/package.json
COPY nuxt.config.js /home/app/nuxt.config.js
COPY nuxt.config-test.js /home/app/nuxt.config-test.js
COPY nuxt.config-prod.js /home/app/nuxt.config-prod.js
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
WORKDIR /home/app
EXPOSE 8080
CMD npm run start
\ No newline at end of file
# admin-yweb
> This is the admin project for yweb
## Build Setup
``` bash
# install dependencies
$ npm install # Or yarn install*[see note below]
# serve with hot reload at localhost:3000
$ npm run dev
# build for production and launch server
$ npm run build
$ npm start
# generate static project
$ npm run generate
```
*Note: Due to a bug in yarn's engine version detection code if you are
using a prerelease version of Node (i.e. v7.6.0-rc.1) you will need to either:
1. Use `npm install`
2. Run `yarn` with a standard release of Node and then switch back
For detailed explanation on how things work, checkout the [Nuxt.js docs](https://github.com/nuxt/nuxt.js).
{
"host":"http:/localhost:3000",
"redis":{
"host":"192.168.20.199",
"pwd":"",
"port":"6379"
},
"logpath":"./",
"uploadImgPath":"http://192.168.20.35:8084"
}
\ No newline at end of file
{
"host":"http://www.yang800.com",
"redis":{
"host":"192.168.187.75",
"pwd":"dd654321",
"port":"6379"
},
"logpath":"/nfs/yang_online/y-web",
"uploadImgPath":"http://admin.yang800.com"
}
\ No newline at end of file
{
"host":"http://webtest.yang800.cn",
"redis":{
"host":"redis.test",
"pwd":"dd654321",
"port":"6379"
},
"logpath":"./",
"uploadImgPath":"http://admintest.yang800.cn"
}
\ No newline at end of file
/*!
* Log.js
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var colors = require('colors');
var fmt = require('util').format;
var EventEmitter = require('events').EventEmitter;
/**
* Initialize a `Loggeer` with the given log `level` defaulting
* to __DEBUG__ and `stream` defaulting to _stdout_.
*
* @param {Number} level
* @param {Object} stream
* @api public
*/
var Log = exports = module.exports = function Log(level, stream){
if ('string' == typeof level) level = exports[level.toUpperCase()];
this.level = isFinite(level) ? level : this.DEBUG;
if(!process.browser) {
this.stream = stream || process.stdout;
if (this.stream.readable) this.read();
}
};
/**
* System is unusable.
*
* @type Number
*/
exports.EMERGENCY = 0;
/**
* Action must be taken immediately.
*
* @type Number
*/
exports.ALERT = 1;
/**
* Critical condition.
*
* @type Number
*/
exports.CRITICAL = 2;
/**
* Error condition.
*
* @type Number
*/
exports.ERROR = 3;
/**
* Warning condition.
*
* @type Number
*/
exports.WARNING = 4;
/**
* Normal but significant condition.
*
* @type Number
*/
exports.NOTICE = 5;
/**
* Purely informational message.
*
* @type Number
*/
exports.INFO = 6;
/**
* Application debug messages.
*
* @type Number
*/
exports.DEBUG = 7;
/**
* prototype.
*/
Log.prototype = {
/**
* Start emitting "line" events.
*
* @api public
*/
read: function(){
var buf = ''
, self = this
, stream = this.stream;
stream.setEncoding('utf8');
stream.on('data', function(chunk){
buf += chunk;
if ('\n' != buf[buf.length - 1]) return;
buf.split('\n').map(function(line){
if (!line.length) return;
try {
var captures = line.match(/^\[([^\]]+)\] (\w+) (.*)/);
var obj = {
date: new Date(captures[1])
, level: exports[captures[2]]
, levelString: captures[2]
, msg: captures[3]
};
self.emit('line', obj);
} catch (err) {
// Ignore
}
});
buf = '';
});
stream.on('end', function(){
self.emit('end');
});
},
isEnable: function(levelStr) {
return exports[levelStr] <= this.level;
},
getTimeStr: function() {
var date = '[' + new Date + ']';
if (this.stream === process.stdout) {
return date.grey;
}
return date;
},
getLevelStr: function(levelStr) {
if (this.stream === process.stdout) {
var result;
switch (levelStr) {
case 'DEBUG':
result = levelStr.cyan;
break;
case 'INFO':
result = levelStr.green;
break;
case 'NOTICE':
result = levelStr.blue;
break;
case 'WARNING':
result = levelStr.yellow;
break;
case 'ERROR':
result = levelStr.red;
break;
case 'CRITICAL':
result = levelStr.red.bold;
break;
case 'ALERT':
result = levelStr.magenta;
break;
case 'EMERGENCY':
result = levelStr.black.bgRed;
break;
default:
result = levelStr;
}
return result;
}
return levelStr;
},
/**
* Log output message.
*
* @param {String} levelStr
* @param {Array} args
* @api private
*/
log: function(levelStr, args) {
if (this.isEnable(levelStr)) {
var msg = fmt.apply(null, args);
if (!process.browser) {
this.stream.write(
this.getTimeStr()
+ ' ' + this.getLevelStr(levelStr)
+ ' ' + msg
+ '\n'
)
console.log(this.getTimeStr()
+ ' ' + this.getLevelStr(levelStr)
+ ' ' + msg)
} else {
if (window.console) {
console.log(this.getTimeStr()
+ ' ' + this.getLevelStr(levelStr)
+ ' ' + msg)
}
}
}
},
/**
* Log emergency `msg`.
*
* @param {String} msg
* @api public
*/
emergency: function(msg){
this.log('EMERGENCY', arguments);
},
/**
* Log alert `msg`.
*
* @param {String} msg
* @api public
*/
alert: function(msg){
this.log('ALERT', arguments);
},
/**
* Log critical `msg`.
*
* @param {String} msg
* @api public
*/
critical: function(msg){
this.log('CRITICAL', arguments);
},
/**
* Log error `msg`.
*
* @param {String} msg
* @api public
*/
error: function(msg){
this.log('ERROR', arguments);
},
/**
* Log warning `msg`.
*
* @param {String} msg
* @api public
*/
warning: function(msg){
this.log('WARNING', arguments);
},
/**
* Log notice `msg`.
*
* @param {String} msg
* @api public
*/
notice: function(msg){
this.log('NOTICE', arguments);
},
/**
* Log info `msg`.
*
* @param {String} msg
* @api public
*/
info: function(msg){
this.log('INFO', arguments);
},
/**
* Log debug `msg`.
*
* @param {String} msg
* @api public
*/
debug: function(msg){
this.log('DEBUG', arguments);
}
};
/**
* Inherit from `EventEmitter`.
*/
Log.prototype.__proto__ = EventEmitter.prototype;
import requestApi from './requestApi.js'
export default {
wxPayInfo: async function (orderSn, cobj, from) {
console.log('支付的订单编号=== ' + orderSn)
let va = navigator.userAgent.toLowerCase()
let inWeixin = false
if (va.indexOf('micromessenger') > 0) {
inWeixin = true
}
let param = {
orderSn: orderSn,
inWeixin: inWeixin
}
let obj = await requestApi.getWxPayInfo(cobj, param)
console.log('getWxPayInfo === ' + JSON.stringify(obj))
if (obj.code === 'success') {
let res = obj.data
if (res.testFlag) {
} else if (res.h5Flag) {
var url = res.data
let host = requestApi.client_getConfig('host')
window.location.href = url + '&redirect_url=' + encodeURI(host + '/order/order?tab=1')
} else {
this.wxPay(JSON.parse(res.data), cobj, from, orderSn)
}
}
},
// 支付
wxPay(res, cobj, from, orderSn) {
let param = {
appId: res.appId,
timeStamp: res.timeStamp,
nonceStr: res.nonceStr,
package: res.package,
signType: res.signType,
paySign: res.paySign
}
console.log()
if (typeof WeixinJSBridge !== 'undefined') {
this.onBridgeReady(param, cobj, from, orderSn)
}
},
onBridgeReady(param, cobj, from, orderSn) {
let that = cobj
WeixinJSBridge.invoke('getBrandWCPayRequest', param, // eslint-disable-line no-undef
function (res) {
// alert('errormsg == ' + JSON.stringify(res))
let success = 1
if (res.err_msg === 'get_brand_wcpay_request:ok') {
success = 0
}
if (from === 1) {
that.$router.push({
path: '/order/pay_success',
query: {
success: success,
orderNo: orderSn
}
})
}
})
}
}
export default {
readLocalCookie(name) {
// console.log('processs == ' + JSON.stringify(process))
// console.log('read cookie' + document.cookie)
let cookieValue = ''
let search = name + '='
if (document.cookie.length > 0) {
let offset = document.cookie.indexOf(search)
if (offset !== -1) {
offset += search.length
let end = document.cookie.indexOf(';', offset)
if (end === -1) {
end = document.cookie.length
}
cookieValue = unescape(document.cookie.substring(offset, end))
}
}
return cookieValue
},
setLocalCookie(name, value) {
this.clearLocalCookie(name)
let ckr = name + '=' + escape(value) + ';'
ckr += 'path=/;'
// console.log('set cookie' + ckr)
document.cookie = ckr
},
clearLocalCookie(name) {
let exp = new Date()
exp.setTime(exp.getTime() - 1)
let cval = this.readLocalCookie(name)
if (cval !== undefined && cval !== null && cval !== '') {
document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString()
}
}
}
module.exports = {
webpack: (config, options, webpack) => {
config.entry.main = './server/index.js'
return config
}
}
<template>
<footer>
Visit our website for more documentation : <a href="https://nuxtjs.org" target="_blank">nuxtjs.org</a>
</footer>
</template>
var gulp = require('gulp')
os = require('os')
path = require('path')
var config = require('./folder.config.json')
var upload = require('./upload.js')
var appConfig = config;
var staticDir = appConfig.staticPath;
var buildDir = appConfig.build
var uploadPrefix = appConfig.uploadPrefix;
/***--------------------useref start ----------------------***/
var uglifyJs = function(file){
console.log('js:' + file);
// if(/\-min.js$/.test(file.path)){
// return false;
// }
// else if(/.js$/.test(file.path)) {
// return true;
// }
return true;
}
gulp.task('uploadImg',function(){
return gulp.src(path.join(staticDir,'**/*{.png, .jpeg, .jpg}'))
.pipe(upload({'uploadPrefix':uploadPrefix,
'baseDir':staticDir}))
.pipe(gulp.dest(buildDir));
});
gulp.task('upload', function(cb) {
gulp.src(path.join(staticDir,'**/*{.png, .jpeg, .jpg}'))
//每一个文件都会执行一次on & .on('data'可以获取匹配到的文件路径 & rename模块也可以获取到
.on('data', function(file) {
console.log(file.path);
});
});
gulp.task('default', ['uploadImg']);
\ No newline at end of file
<template>
<div>
<div>
<div class="head y_flex_between">
<div class="dl-title">管理系统</div>
<div class="dl-log">欢迎您,admin[退出]</div>
</div>
<div class="nav_tab y_flex_start">
<div v-for="(item, index) in tab" :class="{'nav_item': true, 'nav_active': tabNow === index}" @click="switchTab(index)">
{{item}}
</div>
</div>
<div class="y_default_start">
<div class="main_left" :style="{height: clientHeight + 'px'}">
<div class="orderCtg_txt">
<p v-for="(item, index) in orderList" :class="$route.path===item.pagePath?'orderCtg_list_now':''" @click="entriesClick(item)">{{item.name}}</p>
</div>
<div class="orderCtg_txt">
<p v-for="(item, index) in lapsList" :class="$route.path===item.pagePath?'orderCtg_list_now':''" @click="entriesClick(item)">{{item.name}}</p>
</div>
<div class="orderCtg_txt">
<p v-for="(item, index) in financeList" :class="$route.path===item.pagePath?'orderCtg_list_now':''" @click="entriesClick(item)">{{item.name}}</p>
</div>
</div>
<div class="main_right">
<div class="crumbs">
<span class="crumbs_list" v-for="(item, index) in Array.from(visitedViews)">{{item.name}}</span>
</div>
<nuxt class="content"/>
</div>
</div>
</div>
</div>
</template>
<script>
import YCookie from '../assets/js/yCookie.js'
export default {
data() {
return {
tab: ['系统管理', '商品管理', '订单管理', '财务管理'],
tabNow: 0,
orderList: [],
lapsList: [],
financeList: [],
clientHeight: 0
}
},
computed: {
visitedViews() {
// return this.$store.state.systemTags.sVisitedViews
if (this.tabNow === 0) {
return this.$store.state.systemTags.sVisitedViews
} else if (this.tabNow === 1) {
return this.$store.state.goodsTags.gVisitedViews
} else if (this.tabNow === 2) {
return this.$store.state.orderTags.oVisitedViews
} else {
return this.$store.state.financalTags.fVisitedViews
}
}
},
watch: {
$route() {
this.addViewTags()
}
},
methods: {
generateRoute() {
if (this.$route.name) {
return this.$route
}
return false
},
addViewTags() {
const route = this.generateRoute()
if (!route) {
return false
}
// this.$store.dispatch('sAddVisitedViews', route)
if (this.tabNow === 0) {
this.$store.dispatch('sAddVisitedViews', route)
} else if (this.tabNow === 1) {
this.$store.dispatch('gAddVisitedViews', route)
} else if (this.tabNow === 2) {
this.$store.dispatch('oAddVisitedViews', route)
} else {
this.$store.dispatch('fAddVisitedViews', route)
}
},
// 获取列表数据
getOrderCtg() {
let order = []
let orderPath = []
let orderId = []
let laps = []
let lapPath = []
let lapId = []
let finance = []
let accountPath = []
let accountId = []
if (this.tabNow === 0) {
order = ['所有订单']
orderPath = ['/y-order/order']
orderId = ['0']
laps = []
lapPath = []
lapId = []
finance = ['账户安全', '账户信息']
accountPath = ['/account/security', '/account/message']
accountId = ['0', '1']
} else if (this.tabNow === 1) {
order = ['所有订单', '导入订单', '未支付订单']
orderPath = ['/y-order/order', '/y-order/order-import', '/y-order/order-unpaid']
orderId = ['0', '1', '2']
laps = ['账户明细', '采购财务']
lapPath = ['/finance/finance-detail', '/finance/purchase']
lapId = ['0', '2']
finance = ['账户安全', '账户信息']
accountPath = ['/account/security', '/account/message']
accountId = ['0', '1']
} else if (this.tabNow === 2) {
order = ['所有订单', '导入订单', '未支付订单']
orderPath = ['/y-order/order', '/y-order/order-import', '/y-order/order-unpaid']
orderId = ['0', '1', '2']
laps = ['账户明细', '采购财务', '供货财物', '平台分销']
lapPath = ['/finance/finance-detail', '/finance/purchase', '/finance/supply', '/finance/platform']
lapId = ['0', '2', '3', '4']
finance = ['账户安全', '账户信息']
accountPath = ['/account/security', '/account/message']
accountId = ['0', '1']
} else {
order = ['所有订单', '未支付订单']
orderPath = ['/y-order/order', '/y-order/order-unpaid']
orderId = ['0', '2']
laps = ['账户明细', '采购财务', '供货财物', '平台分销']
lapPath = ['/finance/finance-detail', '/finance/purchase', '/finance/supply', '/finance/platform']
lapId = ['0', '2', '3', '4']
finance = ['账户安全', '账户信息']
accountPath = ['/account/security', '/account/message']
accountId = ['0', '1']
}
for (let i = 0; i < order.length; i++) {
let itemOrder = {name: order[i], id: orderId[i], pagePath: orderPath[i]}
this.orderList.push(itemOrder)
}
for (let i = 0; i < laps.length; i++) {
let itemLaps = {name: laps[i], id: lapId[i], pagePath: lapPath[i]}
this.lapsList.push(itemLaps)
}
for (let i = 0; i < finance.length; i++) {
let itemFinance = {name: finance[i], id: accountId[i], pagePath: accountPath[i]}
this.financeList.push(itemFinance)
}
},
switchTab(e) {
this.tabNow = e
YCookie.setLocalCookie('tabNow', this.tabNow)
this.orderList = []
this.lapsList = []
this.financeList = []
this.getOrderCtg()
this.$router.push({
path: '/'
})
console.log(this.$store.state.tagsView.visitedViews)
},
entriesClick(item) {
this.$router.push({
path: item.pagePath
})
console.log(this.$store.state.tagsView.visitedViews)
},
// 获取窗口可视范围的高度
getClientHeight() {
// let clientHeight = 0
// if (document.body.clientHeight && document.documentElement.clientHeight) {
// clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
// } else {
// clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
// }
this.clientHeight = document.documentElement.clientHeight - 76
}
},
mounted() {
this.getClientHeight()
if (YCookie.readLocalCookie('tabNow') === undefined || YCookie.readLocalCookie('tabNow') === '') {
this.tabNow = 0
} else {
this.tabNow = parseInt(YCookie.readLocalCookie('tabNow'))
}
this.getOrderCtg()
this.addViewTags()
}
}
</script>
<style>
.container
{
margin: 0;
width: 100%;
padding: 100px 0;
text-align: center;
}
.button, .button:visited
{
display: inline-block;
color: #3B8070;
letter-spacing: 1px;
background-color: #fff;
border: 2px solid #3B8070;
text-decoration: none;
text-transform: uppercase;
padding: 15px 45px;
}
.button:hover, .button:focus
{
color: #fff;
background-color: #3B8070;
}
.title
{
color: #505153;
font-weight: 300;
font-size: 2.5em;
margin: 0;
}
/*头部*/
.head{
background-color: #1B3160;
height: 36px;
width: 100%;
overflow: hidden;
}
.dl-title {
color: #c1d5ec;
font-family: "Microsoft YaHei";
margin-left: 12px;
font-size: 18px;
line-height: 36px;
}
.dl-log {
color: #C1D5EC;
font-size: 12px;
line-height: 18px;
margin-right: 30px;
}
.nav_tab{
height: 40px;
background: #204077;
}
.nav_item{
color: #D4D4D4;
overflow: hidden;
font-size: 14px;
position: relative;
width: 130px;
padding-left: 8px;
cursor: pointer;
}
.nav_active{
background: #E8E9EE;
color: #43478e;
font-weight: bold;
}
.main_left{
width: 10%;
background: #E8E9EE;
}
.main_right{
width: 90%;
position: relative;
}
.crumbs{
background: #E8E9EE;
width: 100%;
z-index: 1;
overflow: hidden;
height: 21px;
}
.crumbs_list{
border: 1px solid #fff;
margin-right: 15px;
}
.orderCtg_txt{
}
.orderCtg_txt p{
font-size: 14px;
line-height: 20px;
color: #3A3A3A;
padding-left: 20px;
margin-bottom: 4px;
cursor: pointer;
}
.orderCtg_txt .orderCtg_list_now{
color: #C01E00;
position: relative;
min-height: ;
}
.content{
width: 100%;
box-sizing: border-box;
border-top: 1px solid #000;
border-left: 1px solid #000;
position: absolute;
top: 21px;
bottom: 0px;
right: 0px;
}
</style>
<template>
<section class="container">
<img src="../assets/img/logo.png" alt="Nuxt.js Logo" />
<h1 class="title">
{{ error.statusCode }}
</h1>
<h2 class="info">
{{ error.message }}
</h2>
<nuxt-link class="button" to="/" v-if="error.statusCode === 404">
Homepage
</nuxt-link>
</section>
</template>
<script>
export default {
props: ['error']
}
</script>
<style scoped>
.title
{
margin-top: 15px;
font-size: 5em;
}
.info
{
font-weight: 300;
color: #9aabb1;
margin: 0;
}
.button
{
margin-top: 50px;
}
</style>
export default function ({store, redirect}) {
console.log('aut userId' + store.state.auth)
if (store.state.auth === undefined || store.state.auth === null || Object.keys(store.state.auth).length === 0 || store.state.auth.userId === 0) {
redirect('/login/login')
}
}
export default function ({store, redirect}) {
}
export default function ({ route, redirect, store }) {
console.log('route.fullPath == ' + route.fullPath)
if (route.fullPath === '/login') {
store.state.loginPath = store.state.forePath
}
store.state.forePath = route.fullPath
}
var merge = require('webpack-merge')
var baseConfig = require('./nuxt.config.js')
module.exports = merge(baseConfig, {
proxy: {
'/xhr/': 'http://www.yang800.com/backend',
'/order': 'http://www.yang800.com/backend'
}
})
var merge = require('webpack-merge')
var baseConfig = require('./nuxt.config.js')
module.exports = merge(baseConfig, {
proxy: {
'/xhr/': 'http://www.yang800.com/backend',
'/order': 'http://www.yang800.com/backend'
}
})
var merge = require('webpack-merge')
var baseConfig = require('./nuxt.config.js')
module.exports = merge(baseConfig, {
proxy: {
'/xhr/': 'http://yang-web.test:8080',
'/order': 'http://yang-web.test:8080'
}
})
var path = require('path')
module.exports = {
/*
** Headers of the page
*/
head: {
title: '洋800',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' },
{ hid: 'description', name: 'description', content: '洋800是一家专注于跨境电商保税仓的服务商,职责是做您的"正品保税仓",您只需负责挑选进口商品和分享全球好货,我拥有强大的商品、物流团队,让您安心做海外代购专家。洋800拥有各种高品质的进口商品和品牌方,多年来为各大平台提供优质的跨境保税服务,让洋800可以更从容的为您服务,为您带来全新的跨境电商体验,让您瞬间成为国际买手达人。洋800,专业的国际买手服务商。' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
],
script:[{ innerHTML: 'var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id=\'cnzz_stat_icon_1273890888\'%3E%3C/span%3E%3Cscript src=\'" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1273890888%26show%3Dpic\' type=\'text/javascript\'%3E%3C/script%3E"))', type: 'text/javascript', charset: 'utf-8'},
{innerHTML: 'document.write(unescape("%3Cscript src=\'https://hm.baidu.com/hm.js?15740c19dd8c24913adccb501a340e74\' type=\'text/javascript\'%3E%3C/script%3E"))', type: 'text/javascript', charset: 'utf-8'},
{innerHTML: 'document.write(unescape("%3Cscript src=\'https://qiyukf.com/script/d0783d6d8af7d0426096a6c18ffc223e.js\' type=\'text/javascript\'%3E%3C/script%3E"))', type: 'text/javascript', charset: 'utf-8'}],
__dangerouslyDisableSanitizers: ['script']
},
/*
** Global CSS
*/
css: [
'~assets/css/main.css',
'element-ui/lib/theme-chalk/index.css'
// 'vant/lib/vant-css/index.css'
],
/*
** Customize the progress-bar color
*/
loading: {
color: '#3B8070',
duration: 10
},
transition: {
name: 'page',
mode: 'out-in',
duration: 10
},
modules:[
'@nuxtjs/axios'
],
axios: {
proxy: true, // Can be also an object with default options
withCredentials: true
},
plugins: [
// {src: '@/plugins/element-ui'},
{src: '@/plugins/filters'},
{src: '@/plugins/axios'}
],
/*
** Build configuration
*/
build: {
/*
** Run ESLINT on save
*/
extend (config, ctx) {
if (ctx.isClient) {
config.node = {
setImmediate: false,
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
cluster: 'empty',
child_process: 'empty'
}
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: [/(node_modules)/, /(log.js)/, /(vue-page.js)/]
})
}
}
},
router: {
middleware: 'authenticated',
middleware: 'notAuthenticated',
middleware: 'stats'
}
}
{
"name": "admin-yweb",
"version": "1.1.0",
"description": "This is the admin project for yweb",
"author": "YoMon <xumengzhu@edanding.com>",
"private": true,
"scripts": {
"dev": "backpack dev",
"build": "nuxt build && backpack build",
"start": "cross-env NODE_ENV=production node build/main.js",
"precommit": "npm run lint",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore ."
},
"dependencies": {
"@nuxtjs/axios": "5.3.1",
"cross-env": "^5.0.1",
"element-ui": "^2.4.6",
"ioredis": "^4.0.0",
"jsonwebtoken": "^8.3.0",
"koa": "^2.4.1",
"koa-router": "^7.4.0",
"koa-send": "^5.0.0",
"nuxt": "latest",
"source-map-support": "^0.4.15",
"webpack-merge": "^4.1.4"
},
"devDependencies": {
"babel-eslint": "^7.1.1",
"backpack-core": "^0.3.0",
"eslint": "^3.13.1",
"eslint-loader": "^1.9.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-html": "^2.0.3",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-node": "^4.2.2",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^3.0.1",
"nodemon": "^1.11.0",
"scmp": "^2.0.0"
}
}
<template>
<section class="container">
<img src="../assets/img/logo.png" alt="Nuxt.js Logo" class="logo" />
<h1 class="title">
This page is loaded from the {{ name }}
</h1>
<h2 class="info" v-if="name === 'client'">
Please refresh the page
</h2>
<nuxt-link class="button" to="/">
Home page
</nuxt-link>
</section>
</template>
<script>
export default {
asyncData({ req }) {
return {
name: req ? 'server' : 'client'
}
},
head() {
return {
title: `About Page (${this.name}-side)`
}
}
}
</script>
<style scoped>
.title
{
margin-top: 50px;
}
.info
{
font-weight: 300;
color: #9aabb1;
margin: 0;
margin-top: 10px;
}
.button
{
margin-top: 50px;
}
</style>
<template>
<div>
message
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
<template>
<div>
security
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
<template>
<div>
finance-detail
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
<template>
<div>
platform
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
<template>
<div>
purchase
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
<template>
<div>
supply
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
<template>
<section class="container">
<img src="../assets/img/logo.png" alt="Nuxt.js Logo" class="logo" />
<h1 class="title">
Universal Vue.js Application Framework
</h1>
<nuxt-link class="button" to="/about">
About page
</nuxt-link>
</section>
</template>
<style scoped>
.title
{
margin: 50px 0;
}
</style>
<template>
<div>
order-important
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
<template>
<div>
order-unpaid
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
<template>
<div>
order
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
</style>
export default function ({ $axios, req, redirect }) {
$axios.onRequest(config => {
// console.log('tongyong request')
if (req) {
config.headers['y-token'] = req.token
}
})
$axios.onResponse(response => {
if (response) {
// console.log('通用respons插件入口打印')
// if (response.data.errorCode === 401) {
// // 表示没登录,需要登录,,跳转到登录页面
// }
}
})
$axios.onError(error => {
const code = parseInt(error.response && error.response.status)
if (code === 400) {
redirect('/400')
}
})
}
import Vue from 'vue'
import Element from 'element-ui'
export default () => {
Vue.use(Element)
}
import Vue from 'vue'
Date.prototype.format = function (format) { // eslint-disable-line no-extend-native
// console.log('start format ====' + typeof this)
var date = {
'M+': this.getMonth() + 1,
'd+': this.getDate(),
'h+': this.getHours(),
'm+': this.getMinutes(),
's+': this.getSeconds(),
'q+': Math.floor((this.getMonth() + 3) / 3)
}
if (/(y+)/i.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (var k in date) {
if (new RegExp('(' + k + ')').test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? date[k] : ('00' + date[k]).substr(('' + date[k]).length))
}
}
return format
}
export function ymdsTrim(timestamp3) {
if (timestamp3 === 0 || timestamp3 === undefined) {
return ''
}
var newDate = new Date()
newDate.setTime(timestamp3 * 1000)
return newDate.format('yyyy-MM-dd hh:mm:ss')
}
export function ymdTrim(timestamp3) {
if (timestamp3 === 0 || timestamp3 === undefined) {
return ''
}
var newDate = new Date()
newDate.setTime(timestamp3 * 1000)
return newDate.format('yyyy-MM-dd')
}
export function ymTrim(timestamp3) {
if (timestamp3 === 0 || timestamp3 === undefined) {
return ''
}
var newDate = new Date()
newDate.setTime(timestamp3 * 1000)
return newDate.format('yyyy-MM')
}
const filters = {
ymdsTrim, ymdTrim, ymTrim
}
export default filters
Object.keys(filters).forEach(key => {
Vue.filter(key, filters[key])
})
import Koa from 'koa'
import Router from 'koa-router'
import { Nuxt, Builder } from 'nuxt'
import Log from '../assets/js/log.js'
import qs from 'qs'
import requestApi from '../assets/js/requestApi.js'
// const send = require('koa-send')
const fs = require('fs')
var path = require('path')
let logpath = requestApi.server_getConfig('logpath')
var filep = path.join(logpath, 'wlog.log')
console.log(filep)
const stream = fs.createWriteStream(filep, { flags: 'a', defaultEncoding: 'utf8' })
const log = new Log('debug', stream)
const session = require('../session')
const RedisStore = require('../session/RedisStore')
async function start () {
const app = new Koa()
const router = new Router()
// 要区分是线上环境还是开发环境,端口号还有redis都不同
let config = {}
let env = process.env.WD_ENV
let redis = requestApi.server_getConfig('redis')
console.log('get redis info ===' + redis.host + '=====' + redis.pwd + '=====' + redis.port)
let port = process.env.PORT || 3000
log.info('use ' + env + ' configuration')
app.use(session({
store: new RedisStore(redis.host, redis.port, redis.pwd)
}))
if (env === 'production') {
config = require('../nuxt.config-prod.js')
port = process.env.PORT || 8080
config.dev = false
} else if (env === 'test') {
config = require('../nuxt.config-test.js')
port = process.env.PORT || 8080
config.dev = false
} else {
console.log('dev--------')
config = require('../nuxt.config-dev.js')
console.log('config dev --- ====' + config)
config.dev = true
}
console.log('33333')
// Instantiate nuxt.js
const nuxt = new Nuxt(config)
// 生产模式不需要 build
if (config.dev) {
console.log('4444')
const builder = new Builder(nuxt)
await builder.build()
console.log('55555')
}
/* 
router.get('/excel/download', async function(ctx) {
var fileName = ctx.originalUrl
var ls = fileName.split('?name=')
console.dir(ls)
var file = ls[1]
var currFile = path.join('static/file/',file)
console.log('file name === ' + currFile)
// const path = `upload/${name}'
ctx.attachment(currFile)
  await send(ctx, currFile)
})
*/
console.log('2222')
app
.use(router.routes())
.use(router.allowedMethods())
app.use(async (ctx, next) => {
await next()
ctx.status = 200 // koa defaults to 404 when it sees that status is unset
return new Promise((resolve, reject) => {
ctx.res.on('close', resolve)
ctx.res.on('finish', resolve)
log.debug('ctx.request == ' + ctx.req.url + ', ctx.statuscode === ' + ctx.res.statusCode)
nuxt.render(ctx.req, ctx.res, promise => {
// nuxt.render passes a rejected promise into callback on error.
promise.then(resolve).catch(reject)
})
})
})
console.log('111111')
app.listen(port)
console.log('Server listening on '+ ':' + port) // eslint-disable-line no-console
}
start()
const Redis = require('ioredis')
const { randomBytes } = require('crypto')
class RedisStore {
constructor(host, port, pass) {
if(pass ==undefined || pass == '') {
this.redis = new Redis({
host: host,
port: port
})
}
else {
this.redis = new Redis( {
host: host,
port: port,
password: pass
})
}
}
getID(length) {
return randomBytes(length).toString('hex');
}
async get(sid, ctx) {
let data = await this.redis.get(`YSESSION:${sid}`)
return JSON.parse(data)
}
async set(session, { sid = this.getID(24), maxAge= 1000000} = {} , ctx) {
try {
await this.redis.set(`YSESSION:${sid}`, JSON.stringify(session), 'EX', maxAge/1000)
}catch(e) {
}
return sid;
}
async destroy(sid, ctx) {
return await this.redis.del(`YSESSION:${sid}`)
}
}
module.exports = RedisStore
\ No newline at end of file
// id值一旦前台生成,发送给后台,前后台都不会改变这个值,只有前台清除了cookie,会再重新生成,token的刷新还有过期都是用jwt做验证的
const jwt = require('jsonwebtoken')
import Log from '../assets/js/log.js'
import requestApi from '../assets/js/requestApi.js'
const fs = require('fs')
var path = require('path')
let logpath = requestApi.server_getConfig('logpath')
var filep = path.join(logpath, 'session.log')
console.log(filep)
const stream = fs.createWriteStream(filep, { flags: 'a', defaultEncoding: 'utf8' })
const log = new Log('debug', stream)
module.exports = (opts = {}) => {
let env = process.env.WD_ENV
// log.info('session env === ' + env)
let redis = requestApi.server_getConfig('redis')
const { key = "y-token", store = new RedisStore(redis.host, redis.port, redis.pwd) } = opts
return async (ctx, next) => {
let token = ctx.cookies.get(key, opts);
// log.info(ctx.req.url + ' ======token value ==== ' + token)
let id = undefined
let isExpire = false //已过期
let isRefresh = false //需要刷新
let isCreate = false
let sec = 'dd^$token2018'
//如果token存在
if(token) {
try{
let content = jwt.verify(token, sec)
if(content) {
id = content.key
if (ctx.url.indexOf('/xhr') !== -1) {
log.info(ctx.url + '-----------get token key ' + id)
}
if(content.exp) {
if(content.exp < Date.now()/1000) {
isExpire = true
}
else if(content.exp > (content.exp + Date.now()/1000)/2) {
isRefresh = true
}
}
}
}
catch(err) {
ctx.throw(401, 'invalid token')
// log.info('invalid token key ' + id)
}
}
if(!id) {
if (ctx.url.indexOf('/xhr') !== -1) {
log.info(ctx.url + '-----------need create token key ')
}
isCreate = true
ctx.session = {}
}
else {
ctx.session = await store.get(id, ctx)
// console.log('judg type == ' + typeof ctx.session + 'ctx.session === ' + ctx.session + 'keys.lenght === ' + Object.keys(ctx.session).length)
if((typeof ctx.session !== "object" && typeof ctx.session !== 'string') || ctx.session == null || Object.keys(ctx.session).length === 0 ) {
ctx.session = {}
if (ctx.url.indexOf('/xhr') !== -1) {
log.info(ctx.url + '-----------token key1 ' + id)
}
store.destroy(id, ctx)
isCreate = true
// log.info('session has no value ')
}else{
// log.info(ctx.url + '-------session has value-----' + JSON.stringify(ctx.session))
ctx.req.session = ctx.session // for nuxtServerInit
ctx.req.token = token
// store.state.auth = ctx.session
}
}
if(Object.keys(ctx.session).length && ctx.session.nextToken) { //其它请求已经刷新过token了
// console.log('session has been freshed')
token = ctx.session.nextToken
ctx.cookies.set(key, ctx.session.nextToken, opts)
}
else {
if(isCreate || isRefresh || isExpire) {
log.info('session need create ' + isCreate + ',need fresh ' + isRefresh + ', isExpire ' + isExpire)
let expTime = Date.now()/1000 + 7 * 24 * 3600
ctx.session = {userId: 0, userName: '', type: 0}
const sid = await store.set(ctx.session, Object.assign({}, opts, {sid:undefined, exp: expTime}), ctx)
console.log('sid:' + sid)
if(isRefresh) {
ctx.session.nextToken = sid
await store.set(ctx.session, Object.assign({}, opts, {sid:id, maxAge:2800000}), ctx) //原来的key设置为8小时后过期
ctx.session.nextToken = undefined
}
token = jwt.sign({'key':sid, expiresIn: '8h', notBefore:-3600000}, sec)
// log.info('new token value' + token)
ctx.cookies.set(key, token, opts)
}
}
ctx.req.session = ctx.session // for nuxtServerInit
ctx.req.token = token
await next()
ctx.req.token = null
ctx.req.session = null
}
}
const getters = {
sVisitedViews: state => state.systemTags.sVisitedViews,
sCachedViews: state => state.systemTags.sCachedViews,
gVisitedViews: state => state.goodsTags.gVisitedViews,
gCachedViews: state => state.goodsTags.gCachedViews,
oVisitedViews: state => state.goodsTags.oVisitedViews,
oCachedViews: state => state.goodsTags.oCachedViews,
fVisitedViews: state => state.financalTags.fVisitedViews,
fCachedViews: state => state.financalTags.fCachedViews
}
export default getters
import Vue from 'vue'
import Vuex from 'vuex'
import systemTags from './modules/system-tags'
import usrAuth from './modules/usr-auth'
import goodsTags from './modules/goods-tags'
import orderTags from './modules/order-manage-tags'
import financalTags from './modules/financal-tags'
import getters from './getters'
Vue.use(Vuex)
const store = () => {
console.log('creating the store')
return new Vuex.Store({
modules: {
usrAuth,
systemTags,
goodsTags,
orderTags,
financalTags
},
getters
})
}
export default store
const financalTags = {
state: {
fVisitedViews: [],
fCachedViews: []
},
mutations: {
F_ADD_VISITED_VIEWS: (state, view) => {
if (state.fVisitedViews.some(v => v.path === view.path)) return
if (view.path === '/') return
state.fVisitedViews.push(
Object.assign({}, view, {
title: view.meta.title || 'no-name'
})
)
if (!view.meta.noCache) {
state.fCachedViews.push(view.name)
}
},
F_DEL_VISITED_VIEWS: (state, view) => {
for (const [i, v] of state.fVisitedViews.entries()) {
if (v.path === view.path) {
state.fVisitedViews.splice(i, 1)
break
}
}
for (const i of state.fCachedViews) {
if (i === view.name) {
const index = state.fCachedViews.indexOf(i)
state.fCachedViews.splice(index, 1)
break
}
}
},
F_DEL_OTHERS_VIEWS: (state, view) => {
for (const [i, v] of state.fVisitedViews.entries()) {
if (v.path === view.path) {
state.fVisitedViews = state.fVisitedViews.slice(i, i + 1)
break
}
}
for (const i of state.fCachedViews) {
if (i === view.name) {
const index = state.fCachedViews.indexOf(i)
state.fCachedViews = state.fCachedViews.slice(index, index + 1)
break
}
}
},
F_DEL_ALL_VIEWS: state => {
state.sVisitedViews = []
state.fCachedViews = []
}
},
actions: {
fAddVisitedViews({ commit }, view) {
commit('F_ADD_VISITED_VIEWS', view)
},
fDelVisitedViews({ commit, state }, view) {
return new Promise(resolve => {
commit('F_DEL_VISITED_VIEWS', view)
resolve([...state.fVisitedViews])
})
},
fDelOthersViews({ commit, state }, view) {
return new Promise(resolve => {
commit('F_DEL_OTHERS_VIEWS', view)
resolve([...state.fVisitedViews])
})
},
fDelAllViews({ commit, state }) {
return new Promise(resolve => {
commit('F_DEL_ALL_VIEWS')
resolve([...state.fVisitedViews])
})
}
}
}
export default financalTags
const goodsTags = {
state: {
gVisitedViews: [],
gCachedViews: []
},
mutations: {
G_ADD_VISITED_VIEWS: (state, view) => {
if (state.gVisitedViews.some(v => v.path === view.path)) return
if (view.path === '/') return
state.gVisitedViews.push(
Object.assign({}, view, {
title: view.meta.title || 'no-name'
})
)
if (!view.meta.noCache) {
state.gCachedViews.push(view.name)
}
},
G_DEL_VISITED_VIEWS: (state, view) => {
for (const [i, v] of state.gVisitedViews.entries()) {
if (v.path === view.path) {
state.gVisitedViews.splice(i, 1)
break
}
}
for (const i of state.gCachedViews) {
if (i === view.name) {
const index = state.gCachedViews.indexOf(i)
state.gCachedViews.splice(index, 1)
break
}
}
},
G_DEL_OTHERS_VIEWS: (state, view) => {
for (const [i, v] of state.gVisitedViews.entries()) {
if (v.path === view.path) {
state.gVisitedViews = state.gVisitedViews.slice(i, i + 1)
break
}
}
for (const i of state.gCachedViews) {
if (i === view.name) {
const index = state.gCachedViews.indexOf(i)
state.gCachedViews = state.gCachedViews.slice(index, index + 1)
break
}
}
},
G_DEL_ALL_VIEWS: state => {
state.gVisitedViews = []
state.gCachedViews = []
}
},
actions: {
gaddVisitedViews({ commit }, view) {
commit('G_ADD_VISITED_VIEWS', view)
},
gdelVisitedViews({ commit, state }, view) {
return new Promise(resolve => {
commit('G_DEL_VISITED_VIEWS', view)
resolve([...state.gVisitedViews])
})
},
gdelOthersViews({ commit, state }, view) {
return new Promise(resolve => {
commit('G_DEL_OTHERS_VIEWS', view)
resolve([...state.gVisitedViews])
})
},
gdelAllViews({ commit, state }) {
return new Promise(resolve => {
commit('G_DEL_ALL_VIEWS')
resolve([...state.gVisitedViews])
})
}
}
}
export default goodsTags
const orderTags = {
state: {
oVisitedViews: [],
oCachedViews: []
},
mutations: {
O_ADD_VISITED_VIEWS: (state, view) => {
if (state.oVisitedViews.some(v => v.path === view.path)) return
if (view.path === '/') return
state.oVisitedViews.push(
Object.assign({}, view, {
title: view.meta.title || 'no-name'
})
)
if (!view.meta.noCache) {
state.oCachedViews.push(view.name)
}
},
O_DEL_VISITED_VIEWS: (state, view) => {
for (const [i, v] of state.oVisitedViews.entries()) {
if (v.path === view.path) {
state.oVisitedViews.splice(i, 1)
break
}
}
for (const i of state.oCachedViews) {
if (i === view.name) {
const index = state.oCachedViews.indexOf(i)
state.oCachedViews.splice(index, 1)
break
}
}
},
O_DEL_OTHERS_VIEWS: (state, view) => {
for (const [i, v] of state.oVisitedViews.entries()) {
if (v.path === view.path) {
state.oVisitedViews = state.oVisitedViews.slice(i, i + 1)
break
}
}
for (const i of state.oCachedViews) {
if (i === view.name) {
const index = state.oCachedViews.indexOf(i)
state.oCachedViews = state.oCachedViews.slice(index, index + 1)
break
}
}
},
O_DEL_ALL_VIEWS: state => {
state.oVisitedViews = []
state.oCachedViews = []
}
},
actions: {
oAddVisitedViews({ commit }, view) {
commit('O_ADD_VISITED_VIEWS', view)
},
oDelVisitedViews({ commit, state }, view) {
return new Promise(resolve => {
commit('O_DEL_VISITED_VIEWS', view)
resolve([...state.visitedViews])
})
},
oDelOthersViews({ commit, state }, view) {
return new Promise(resolve => {
commit('O_DEL_OTHERS_VIEWS', view)
resolve([...state.oVisitedViews])
})
},
oDelAllViews({ commit, state }) {
return new Promise(resolve => {
commit('O_DEL_ALL_VIEWS')
resolve([...state.oVisitedViews])
})
}
}
}
export default orderTags
\ No newline at end of file
const systemTags = {
state: {
sVisitedViews: [],
sCachedViews: []
},
mutations: {
S_ADD_VISITED_VIEWS: (state, view) => {
if (state.sVisitedViews.some(v => v.path === view.path)) return
if (view.path === '/') return
state.sVisitedViews.push(
Object.assign({}, view, {
title: view.meta.title || 'no-name'
})
)
if (!view.meta.noCache) {
state.sCachedViews.push(view.name)
}
},
S_DEL_VISITED_VIEWS: (state, view) => {
for (const [i, v] of state.sVisitedViews.entries()) {
if (v.path === view.path) {
state.sVisitedViews.splice(i, 1)
break
}
}
for (const i of state.sCachedViews) {
if (i === view.name) {
const index = state.sCachedViews.indexOf(i)
state.sCachedViews.splice(index, 1)
break
}
}
},
S_DEL_OTHERS_VIEWS: (state, view) => {
for (const [i, v] of state.sVisitedViews.entries()) {
if (v.path === view.path) {
state.sVisitedViews = state.sVisitedViews.slice(i, i + 1)
break
}
}
for (const i of state.sCachedViews) {
if (i === view.name) {
const index = state.sCachedViews.indexOf(i)
state.sCachedViews = state.sCachedViews.slice(index, index + 1)
break
}
}
},
S_DEL_ALL_VIEWS: state => {
state.sVisitedViews = []
state.sCachedViews = []
}
},
actions: {
sAddVisitedViews({ commit }, view) {
commit('S_ADD_VISITED_VIEWS', view)
},
sDelVisitedViews({ commit, state }, view) {
return new Promise(resolve => {
commit('S_DEL_VISITED_VIEWS', view)
resolve([...state.sVisitedViews])
})
},
sDelOthersViews({ commit, state }, view) {
return new Promise(resolve => {
commit('S_DEL_OTHERS_VIEWS', view)
resolve([...state.sVisitedViews])
})
},
sDelAllViews({ commit, state }) {
return new Promise(resolve => {
commit('S_DEL_ALL_VIEWS')
resolve([...state.sVisitedViews])
})
}
}
}
export default systemTags
const usrAuth = {
state: {
auth: null,
forePath: '',
loginPath: '',
isAuth: 'false',
keyword: ''
},
mutations: {
identyAuth(state, authInfo) {
state.auth = authInfo
if (authInfo === undefined || authInfo === null || Object.keys(authInfo).length === 0 || authInfo.userId < 1) {
state.isAuth = false
console.log('isAuth === false')
} else {
state.isAuth = true
console.log('isAuth === true')
}
},
cancelAuth(state) {
state.auth = {userId: 0, userName: ''}
},
storeKeyword(state, skeyword) {
state.keyword = skeyword
}
},
actions: {
identyAuth: ({ commit }) => commit('identyAuth'),
cancelAuth: ({ commit }) => commit('cancelAuth'),
storeKeyword: ({ commit }) => commit('storeKeyword'),
nuxtServerInit({commit}, {req}) {
console.log('页面重载')
let accessToken = null
console.log('cookie1111:' + JSON.stringify(req.session) + 'userId==' + typeof req.session)
let session = req.session
if (typeof req.session === 'string') {
session = JSON.parse(req.session)
}
if (session && session.userId !== undefined && session.userId !== null && session.userId > 0) {
console.log('enter this store')
var parsed = session
accessToken = parsed
}
console.log('cookie:' + accessToken)
commit('identyAuth', accessToken)
console.log('state:' + JSON.stringify(this.state))
}
}
}
export default usrAuth
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment