完成admin多页迁移

This commit is contained in:
zema1 2017-11-13 10:12:11 +08:00
parent aae172ddf5
commit 1910fc3bb0
132 changed files with 264 additions and 940 deletions

78
.gitignore vendored
View File

@ -1,10 +1,70 @@
.DS_Store # Logs
node_modules/ logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
dist/ dist/
npm-debug.log
npm-debug.log.* # Dependency directories
test/unit/coverage node_modules/
test/e2e/reports jspm_packages/
selenium-debug.log
.idea/ # Typescript v1 declaration files
stat.json typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# editor
.vscode
.idea
# test_code
test.vue
# build
vendor-manifest.json
vendor.dll.js

View File

@ -1,18 +0,0 @@
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2"
],
"plugins": ["transform-runtime"],
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": ["istanbul"]
}
}
}

View File

@ -1,22 +0,0 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
}
}

View File

@ -1,105 +0,0 @@
'use strict'
require('./check-versions')()
const config = require('../config')
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
}
const opn = require('opn')
const path = require('path')
const express = require('express')
const webpack = require('webpack')
const proxyMiddleware = require('http-proxy-middleware')
const webpackConfig = require('./webpack.dev.conf')
// default port where dev server listens for incoming traffic
const port = process.env.PORT || config.dev.port
// automatically open browser, if not set will be false
const autoOpenBrowser = !!config.dev.autoOpenBrowser
// Define HTTP proxies to your custom API backend
// https://github.com/chimurai/http-proxy-middleware
const proxyTable = config.dev.proxyTable
const app = express()
const compiler = webpack(webpackConfig)
const devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
quiet: true
})
const hotMiddleware = require('webpack-hot-middleware')(compiler, {
log: false,
heartbeat: 2000
})
// force page reload when html-webpack-plugin template changes
// currently disabled until this is resolved:
// https://github.com/jantimon/html-webpack-plugin/issues/680
// compiler.plugin('compilation', function (compilation) {
// compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
// hotMiddleware.publish({ action: 'reload' })
// cb()
// })
// })
// enable hot-reload and state-preserving
// compilation error display
app.use(hotMiddleware)
// proxy api requests
Object.keys(proxyTable).forEach(function (context) {
let 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)
// serve pure static assets
const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static'))
const uri = 'http://localhost:' + port
var _resolve
var _reject
var readyPromise = new Promise((resolve, reject) => {
_resolve = resolve
_reject = reject
})
var server
var portfinder = require('portfinder')
portfinder.basePort = port
console.log('> Starting dev server...')
devMiddleware.waitUntilValid(() => {
portfinder.getPort((err, port) => {
if (err) {
_reject(err)
}
process.env.PORT = port
var uri = 'http://localhost:' + port
console.log('> Listening at ' + uri + '\n')
// when env is testing, don't need open it
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
opn(uri)
}
server = app.listen(port)
_resolve()
})
})
module.exports = {
ready: readyPromise,
close: () => {
server.close()
}
}

View File

@ -1,72 +0,0 @@
'use strict'
const path = require('path')
const config = require('../config')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
exports.assetsPath = function (_path) {
const assetsSubDirectory = process.env.NODE_ENV === 'production'
? config.build.assetsSubDirectory
: config.dev.assetsSubDirectory
return path.posix.join(assetsSubDirectory, _path)
}
exports.cssLoaders = function (options) {
options = options || {}
const 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) {
const 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) {
const output = []
const loaders = exports.cssLoaders(options)
for (const extension in loaders) {
const loader = loaders[extension]
output.push({
test: new RegExp('\\.' + extension + '$'),
use: loader
})
}
return output
}

View File

@ -1,75 +0,0 @@
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
module.exports = {
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'),
}
},
module: {
rules: [
{
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src'), resolve('test')],
options: {
formatter: require('eslint-friendly-formatter')
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
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: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
}
}

View File

@ -1,36 +0,0 @@
'use strict'
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.conf')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const 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()
]
})

View File

@ -1,124 +0,0 @@
'use strict'
const path = require('path')
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const env = config.build.env
const 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
}),
// UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minify
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'
}),
// keep module.id stable when vender modules does not change
new webpack.HashedModuleIdsPlugin(),
// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
// 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) {
const 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) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
}
module.exports = webpackConfig

View File

@ -1,7 +0,0 @@
'use strict'
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')
module.exports = merge(prodEnv, {
NODE_ENV: '"development"'
})

View File

@ -1,51 +0,0 @@
'use strict'
// Template version: 1.1.3
// see http://vuejs-templates.github.io/webpack for documentation.
const 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: '/admin/',
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'),
port: 8010,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
"/api": {
target: process.env.TARGET,
changeOrigin: true
},
"/static/upload": {
target: process.env.TARGET,
changeOrigin: true
}
},
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false
}
}

View File

@ -1,10 +0,0 @@
let date = require('moment')().format('YYYYMMDD')
let commit = require('child_process').execSync('git rev-parse HEAD').toString().slice(0, 5)
let version = `"${date}-${commit}"`
console.log(`current version is ${version}`)
module.exports = {
NODE_ENV: '"production"',
VERSION: version
}

View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>OnlineJudge Admin</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="renderer" content="webkit" />
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

View File

@ -1,82 +0,0 @@
{
"name": "oj_admin",
"version": "1.0.0",
"description": "onlinejudge admin",
"author": "zemal <rawidn@163.com>",
"private": true,
"scripts": {
"dev": "node build/dev-server.js",
"start": "npm run dev",
"build": "node build/build.js",
"lint": "eslint --ext .js,.vue src"
},
"dependencies": {
"axios": "^0.17.0",
"element-ui": "^1.4.9",
"font-awesome": "^4.7.0",
"moment": "^2.19.1",
"simditor": "^2.3.6",
"simditor-markdown": "^1.1.2",
"vue": "^2.5.3",
"vue-codemirror": "^3.1.8",
"vue-i18n": "^7.3.2",
"vue-router": "^2.8.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-eslint": "^7.1.1",
"babel-loader": "^7.1.1",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chalk": "^2.0.1",
"connect-history-api-fallback": "^1.3.0",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"eslint": "^3.19.0",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^3.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^3.0.1",
"eventsource-polyfill": "^0.9.6",
"express": "^4.14.1",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"http-proxy-middleware": "^0.17.3",
"less": "^2.7.2",
"less-loader": "^4.0.5",
"opn": "^5.1.0",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"url-loader": "^0.5.8",
"vue-loader": "^13.5.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.3",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-middleware": "^1.12.0",
"webpack-hot-middleware": "^2.18.2",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 4.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}

View File

@ -1,5 +0,0 @@
export const CONTEST_STATUS_REVERSE = {
'-1': 'Ended',
'0': 'Underway',
'1': 'Not Started'
}

View File

@ -1,25 +0,0 @@
import moment from 'moment'
// 友好显示时间
export function fromNow (time) {
return moment(time * 3).fromNow()
}
// 只显示日期
export function onlyDate (time) {
const d = new Date(time * 1000)
return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
}
function localtime (utcTime, format = 'YYYY-M-D HH:mm:ss') {
let m = moment.utc(utcTime)
if (m.isValid()) {
return m.local().format(format)
} else {
return ''
}
}
export default {
localtime: localtime
}

View File

View File

@ -57,7 +57,14 @@ Object.keys(proxyTable).forEach(function (context) {
}) })
// handle fallback for HTML5 history API // handle fallback for HTML5 history API
app.use(require('connect-history-api-fallback')()) const rewrites = {
rewrites: [{
from: '/admin/', // 正则或者字符串
to: '/admin/index.html', // 字符串或者函数
}]
}
const historyMiddleware = require('connect-history-api-fallback')(rewrites);
app.use(historyMiddleware)
// serve webpack bundle output // serve webpack bundle output
app.use(devMiddleware) app.use(devMiddleware)

View File

@ -4,6 +4,7 @@ const webpack = require('webpack')
const utils = require('./utils') const utils = require('./utils')
const config = require('../config') const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf') const vueLoaderConfig = require('./vue-loader.conf')
const HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plugin')
function resolve (dir) { function resolve (dir) {
return path.join(__dirname, '..', dir) return path.join(__dirname, '..', dir)
@ -11,7 +12,8 @@ function resolve (dir) {
module.exports = { module.exports = {
entry: { entry: {
'admin': './src/pages/oj/index.js' 'oj': './src/pages/oj/index.js',
'admin': './src/pages/admin/index.js'
}, },
output: { output: {
path: config.build.assetsRoot, path: config.build.assetsRoot,
@ -37,7 +39,7 @@ module.exports = {
test: /\.(js|vue)$/, test: /\.(js|vue)$/,
loader: 'eslint-loader', loader: 'eslint-loader',
enforce: 'pre', enforce: 'pre',
include: [resolve('src'), resolve('test')], include: [resolve('src')],
options: { options: {
formatter: require('eslint-friendly-formatter') formatter: require('eslint-friendly-formatter')
} }
@ -80,6 +82,16 @@ module.exports = {
] ]
}, },
plugins: [ plugins: [
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /zh-cn/) new webpack.DllReferencePlugin({
name: 'vendor_dll',
context: __dirname,
manifest: require('./vendor-manifest.json')
}),
new HtmlWebpackIncludeAssetsPlugin({
assets: ['static/js/vendor.dll.js'],
files: ['index.html', 'admin/index.html'],
append: false,
hash: true
}),
] ]
} }

View File

@ -30,6 +30,12 @@ module.exports = merge(baseWebpackConfig, {
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
filename: config.build.ojIndex, filename: config.build.ojIndex,
template: config.build.ojTemplate, template: config.build.ojTemplate,
chunks: ['manifest', 'vendor', 'oj'],
inject: true
}),
new HtmlWebpackPlugin({
filename: config.build.adminIndex,
template: config.build.adminTemplate,
chunks: ['manifest', 'vendor', 'admin'], chunks: ['manifest', 'vendor', 'admin'],
inject: true inject: true
}), }),

43
build/webpack.dll.conf.js Normal file
View File

@ -0,0 +1,43 @@
const webpack = require('webpack');
const path = require('path');
const UglifyJsParallelPlugin = require('webpack-uglify-parallel');
const os = require('os');
const vendors = [
'vue/dist/vue.esm.js',
'vue-router',
'vuex',
'axios',
'moment'
];
module.exports = {
entry: {
"vendor": vendors,
},
output: {
path: path.join(__dirname, '../static/js'),
filename: '[name].dll.js',
library: '[name]_dll',
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /zh-cn/),
new UglifyJsParallelPlugin({
workers: os.cpus().length,
mangle: true,
exclude: /\.min\.js$/,
output: {comments: false},
compressor: {
warnings: false,
drop_console: true,
drop_debugger: true
}
}),
new webpack.DllPlugin({
context: __dirname,
path: path.join(__dirname, '[name]-manifest.json'),
name: '[name]_dll',
})
]
};

View File

@ -1,4 +1,5 @@
'use strict' 'use strict'
const os = require('os');
const path = require('path') const path = require('path')
const utils = require('./utils') const utils = require('./utils')
const webpack = require('webpack') const webpack = require('webpack')
@ -9,6 +10,7 @@ const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin') const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsParallelPlugin = require('webpack-uglify-parallel');
const env = config.build.env const env = config.build.env
@ -31,11 +33,16 @@ const webpackConfig = merge(baseWebpackConfig, {
'process.env': env 'process.env': env
}), }),
// UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minify // UglifyJs do not support ES6+, you can also use babel-minify for better treeshaking: https://github.com/babel/minify
new webpack.optimize.UglifyJsPlugin({ new UglifyJsParallelPlugin({
compress: { workers: os.cpus().length,
warnings: false mangle: true,
}, exclude: /\.min\.js$/,
sourceMap: true output: {comments: false},
compressor: {
warnings: false,
drop_console: true,
drop_debugger: true
}
}), }),
// extract css into its own file // extract css into its own file
new ExtractTextPlugin({ new ExtractTextPlugin({
@ -52,6 +59,7 @@ const webpackConfig = merge(baseWebpackConfig, {
// generate dist index.html with correct asset hash for caching. // generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html // you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin // see https://github.com/ampedandwired/html-webpack-plugin
// oj
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
filename: config.build.ojIndex, filename: config.build.ojIndex,
template: config.build.ojTemplate, template: config.build.ojTemplate,
@ -66,28 +74,45 @@ const webpackConfig = merge(baseWebpackConfig, {
// necessary to consistently work with multiple chunks via CommonsChunkPlugin // necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency' chunksSortMode: 'dependency'
}), }),
// admin
new HtmlWebpackPlugin({
filename: config.build.adminIndex,
template: config.build.adminTemplate,
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'
}),
// keep module.id stable when vender modules does not change // keep module.id stable when vender modules does not change
new webpack.HashedModuleIdsPlugin(), new webpack.HashedModuleIdsPlugin(),
// split vendor js into its own file // split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({ new webpack.optimize.CommonsChunkPlugin({
name: 'vendor', name: 'common',
minChunks: function (module) { chunks: ['oj', 'admin'],
// any required modules inside node_modules are extracted to vendor minChunks: 2
return ( // minChunks: function (module) {
module.resource && // // any required modules inside node_modules are extracted to vendor
/\.js$/.test(module.resource) && // return (
module.resource.indexOf( // module.resource &&
path.join(__dirname, '../node_modules') // /\.js$/.test(module.resource) &&
) === 0 // module.resource.indexOf(
) // path.join(__dirname, '../node_modules')
} // ) === 0
// )
// }
}), }),
// extract webpack runtime and module manifest to its own file in order to // extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated // prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({ new webpack.optimize.CommonsChunkPlugin({
name: 'manifest', name: 'manifest',
chunks: ['vendor'] chunks: ['common']
}), }),
// copy custom static assets // copy custom static assets
new CopyWebpackPlugin([ new CopyWebpackPlugin([

View File

@ -1,9 +0,0 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

View File

@ -1,2 +0,0 @@
build/*.js
config/*.js

64
oj/.gitignore vendored
View File

@ -1,64 +0,0 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Typescript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# vscode
.vscode
# test_code
test.vue

View File

@ -1,41 +0,0 @@
'use strict'
require('./check-versions')()
process.env.NODE_ENV = 'production'
const ora = require('ora')
const rm = require('rimraf')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const config = require('../config')
const webpackConfig = require('./webpack.prod.conf')
const 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')
if (stats.hasErrors()) {
console.log(chalk.red(' Build failed with errors.\n'))
process.exit(1)
}
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'
))
})
})

View File

@ -1,49 +0,0 @@
'use strict'
const chalk = require('chalk')
const semver = require('semver')
const packageConfig = require('../package.json')
const shell = require('shelljs')
function exec (cmd) {
return require('child_process').execSync(cmd).toString().trim()
}
const 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 () {
const warnings = []
for (let i = 0; i < versionRequirements.length; i++) {
const 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 (let i = 0; i < warnings.length; i++) {
const warning = warnings[i]
console.log(' ' + warning)
}
console.log()
process.exit(1)
}
}

View File

@ -1,10 +0,0 @@
/* eslint-disable */
'use strict'
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()
}
})

View File

@ -1,19 +0,0 @@
'use strict'
const utils = require('./utils')
const config = require('../config')
const isProduction = process.env.NODE_ENV === 'production'
module.exports = {
loaders: utils.cssLoaders({
sourceMap: isProduction
? config.build.productionSourceMap
: config.dev.cssSourceMap,
extract: isProduction
}),
transformToRequire: {
video: 'src',
source: 'src',
img: 'src',
image: 'xlink:href'
}
}

File diff suppressed because one or more lines are too long

View File

@ -8,15 +8,20 @@
"dev": "node build/dev-server.js", "dev": "node build/dev-server.js",
"start": "npm run dev", "start": "npm run dev",
"build": "node build/build.js", "build": "node build/build.js",
"build:dll": "webpack --config=build/webpack.dll.conf.js",
"lint": "eslint --ext .js,.vue src" "lint": "eslint --ext .js,.vue src"
}, },
"dependencies": { "dependencies": {
"axios": "^0.17.0", "axios": "^0.17.0",
"browser-detect": "^0.2.18", "browser-detect": "^0.2.18",
"echarts": "^3.8.3", "echarts": "^3.8.3",
"element-ui": "^1.4.9",
"font-awesome": "^4.7.0",
"highlight.js": "^9.12.0", "highlight.js": "^9.12.0",
"iview": "^2.6.0", "iview": "^2.6.0",
"moment": "^2.19.1", "moment": "^2.19.1",
"simditor": "^2.3.6",
"simditor-markdown": "^1.1.2",
"vue": "^2.5.3", "vue": "^2.5.3",
"vue-clipboard2": "0.0.7", "vue-clipboard2": "0.0.7",
"vue-codemirror-lite": "^1.0.2", "vue-codemirror-lite": "^1.0.2",
@ -54,6 +59,7 @@
"extract-text-webpack-plugin": "^3.0.0", "extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4", "file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1", "friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-include-assets-plugin": "^1.0.2",
"html-webpack-plugin": "^2.30.1", "html-webpack-plugin": "^2.30.1",
"http-proxy-middleware": "^0.17.3", "http-proxy-middleware": "^0.17.3",
"less": "^2.7.3", "less": "^2.7.3",
@ -73,7 +79,8 @@
"webpack-bundle-analyzer": "^2.9.0", "webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-middleware": "^1.12.0", "webpack-dev-middleware": "^1.12.0",
"webpack-hot-middleware": "^2.18.2", "webpack-hot-middleware": "^2.18.2",
"webpack-merge": "^4.1.0" "webpack-merge": "^4.1.0",
"webpack-uglify-parallel": "^0.1.4"
}, },
"engines": { "engines": {
"node": ">= 4.0.0", "node": ">= 4.0.0",

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -1,7 +1,7 @@
<template> <template>
<el-menu default-active="1" class="vertical_menu" theme="dark" :router="true" :default-active="currentPath" style="overflow: auto"> <el-menu default-active="1" class="vertical_menu" theme="dark" :router="true" :default-active="currentPath" style="overflow: auto">
<div class="logo"> <div class="logo">
<img src="../assets/logo.svg" alt="oj admin" /> <img src="../../../assets/logo.svg" alt="oj admin" />
</div> </div>
<el-submenu index="general"> <el-submenu index="general">
<template slot="title"><i class="el-icon-menu"></i>General</template> <template slot="title"><i class="el-icon-menu"></i>General</template>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>OnlineJudge</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="renderer" content="webkit"/>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

View File

@ -1,10 +1,10 @@
import Vue from 'vue' import Vue from 'vue'
import App from './App' import App from './App.vue'
import Element from 'element-ui' import Element from 'element-ui'
import 'element-ui/lib/theme-default/index.css' import 'element-ui/lib/theme-default/index.css'
import locale from 'element-ui/lib/locale/lang/en' import locale from 'element-ui/lib/locale/lang/en'
import filters from './utils/filters.js' import filters from '@/utils/filters'
import router from './router' import router from './router'
import Panel from './components/Panel.vue' import Panel from './components/Panel.vue'

View File

@ -1,18 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import VueRouter from 'vue-router' import VueRouter from 'vue-router'
// 引入 view 组件 // 引入 view 组件
import { import { Announcement, Conf, Contest, ContestList, Home, JudgeServer, Login, Problem, ProblemList, User } from './views'
Announcement,
Conf,
Contest,
ContestList,
Home,
JudgeServer,
Login,
Problem,
ProblemList,
User
} from './views'
Vue.use(VueRouter) Vue.use(VueRouter)
@ -103,10 +92,12 @@ export default new VueRouter({
path: '/contest/:contestId/problem/:problemId/edit', path: '/contest/:contestId/problem/:problemId/edit',
name: 'edit-contest-problem', name: 'edit-contest-problem',
component: Problem component: Problem
},
{
path: '*', redirect: '/problem-list'
} }
] ]
}] },
{
path: '*', redirect: '/login'
}
]
}) })

View File

@ -95,7 +95,7 @@
<script> <script>
import api from '../../api.js' import api from '../../api.js'
import { CONTEST_STATUS_REVERSE } from '../../utils/constants' import { CONTEST_STATUS_REVERSE } from '@/utils/constants'
export default { export default {
name: 'ContestList', name: 'ContestList',

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="view"> <div class="view">
<Panel title="User List"> <Panel title="User ">
<div slot="header"> <div slot="header">
<el-input <el-input
v-model="keyword" v-model="keyword"

View File

@ -18,7 +18,7 @@
<script> <script>
import { mapActions, mapState } from 'vuex' import { mapActions, mapState } from 'vuex'
import NavBar from '~/NavBar.vue' import NavBar from '@oj/components/NavBar.vue'
export default { export default {
name: 'app', name: 'app',

View File

@ -39,7 +39,7 @@
</script> </script>
<style lang="less"> <style lang="less">
@import (reference) '../styles/common.less'; @import (reference) '../../../styles/common.less';
.panel-title { .panel-title {
.section-title; .section-title;

View File

@ -5,7 +5,7 @@
</template> </template>
<script> <script>
import {Emitter} from '~/mixins' import Emitter from '../mixins/emitter'
export default { export default {
name: 'VerticalMenu-item', name: 'VerticalMenu-item',

View File

@ -8,9 +8,9 @@ import locale from 'iview/src/locale/lang/en-US'
import iView from 'iview' import iView from 'iview'
import 'iview/dist/styles/iview.css' import 'iview/dist/styles/iview.css'
import Panel from '~/Panel.vue' import Panel from '@oj/components/Panel.vue'
import VerticalMenu from '~/verticalMenu/verticalMenu.vue' import VerticalMenu from '@oj/components/verticalMenu/verticalMenu.vue'
import VerticalMenuItem from '~/verticalMenu/verticalMenu-item.vue' import VerticalMenuItem from '@oj/components/verticalMenu/verticalMenu-item.vue'
import '@/styles/index.less' import '@/styles/index.less'
import filters from '@/utils/filters.js' import filters from '@/utils/filters.js'

View File

@ -1,7 +1,7 @@
import moment from 'moment' import moment from 'moment'
import types from '../types' import types from '../types'
import api from '@oj/api' import api from '@oj/api'
import { CONTEST_STATUS_REVERSE, USER_TYPE, CONTEST_TYPE } from '@/utils/constants' import { CONTEST_STATUS, USER_TYPE, CONTEST_TYPE } from '@/utils/constants'
const state = { const state = {
now: new Date(), now: new Date(),
@ -28,11 +28,11 @@ const getters = {
let now = state.now let now = state.now
if (startTime > now) { if (startTime > now) {
return CONTEST_STATUS_REVERSE.NOT_START return CONTEST_STATUS.NOT_START
} else if (endTime < now) { } else if (endTime < now) {
return CONTEST_STATUS_REVERSE.ENDED return CONTEST_STATUS.ENDED
} else { } else {
return CONTEST_STATUS_REVERSE.UNDERWAY return CONTEST_STATUS.UNDERWAY
} }
}, },
contestRuleType: (state) => { contestRuleType: (state) => {
@ -45,20 +45,20 @@ const getters = {
contestMenuDisabled: (state, getters) => { contestMenuDisabled: (state, getters) => {
if (getters.isContestAdmin) return false if (getters.isContestAdmin) return false
if (state.contest.contest_type === CONTEST_TYPE.PUBLIC) { if (state.contest.contest_type === CONTEST_TYPE.PUBLIC) {
return getters.contestStatus === CONTEST_STATUS_REVERSE.NOT_START return getters.contestStatus === CONTEST_STATUS.NOT_START
} }
return !state.access return !state.access
}, },
OIContestRealTimePermission: (state, getters, _, rootGetters) => { OIContestRealTimePermission: (state, getters, _, rootGetters) => {
if (getters.contestRuleType === 'ACM' || getters.contestStatus === CONTEST_STATUS_REVERSE.ENDED) { if (getters.contestRuleType === 'ACM' || getters.contestStatus === CONTEST_STATUS.ENDED) {
return true return true
} }
return state.contest.real_time_rank === true || getters.isContestAdmin return state.contest.real_time_rank === true || getters.isContestAdmin
}, },
problemSubmitDisabled: (state, getters, _, rootGetters) => { problemSubmitDisabled: (state, getters, _, rootGetters) => {
if (getters.contestStatus === CONTEST_STATUS_REVERSE.ENDED) { if (getters.contestStatus === CONTEST_STATUS.ENDED) {
return true return true
} else if (getters.contestStatus === CONTEST_STATUS_REVERSE.NOT_START) { } else if (getters.contestStatus === CONTEST_STATUS.NOT_START) {
return !getters.isContestAdmin return !getters.isContestAdmin
} }
return !rootGetters.isAuthenticated return !rootGetters.isAuthenticated
@ -73,7 +73,7 @@ const getters = {
return moment(state.contest.end_time) return moment(state.contest.end_time)
}, },
countdown: (state, getters) => { countdown: (state, getters) => {
if (getters.contestStatus === CONTEST_STATUS_REVERSE.NOT_START) { if (getters.contestStatus === CONTEST_STATUS.NOT_START) {
let duration = moment.duration(getters.contestStartTime.diff(state.now, 'seconds'), 'seconds') let duration = moment.duration(getters.contestStartTime.diff(state.now, 'seconds'), 'seconds')
// time is too long // time is too long
if (duration.weeks() > 0) { if (duration.weeks() > 0) {
@ -81,7 +81,7 @@ const getters = {
} }
let texts = [duration.hours(), duration.minutes(), duration.seconds()] let texts = [duration.hours(), duration.minutes(), duration.seconds()]
return '-' + texts.join(':') return '-' + texts.join(':')
} else if (getters.contestStatus === CONTEST_STATUS_REVERSE.UNDERWAY) { } else if (getters.contestStatus === CONTEST_STATUS.UNDERWAY) {
let duration = moment.duration(getters.contestEndTime.diff(state.now, 'seconds'), 'seconds') let duration = moment.duration(getters.contestEndTime.diff(state.now, 'seconds'), 'seconds')
let texts = [duration.asHours().toFixed(0), duration.minutes(), duration.seconds()] let texts = [duration.asHours().toFixed(0), duration.minutes(), duration.seconds()]
return '-' + texts.join(':') return '-' + texts.join(':')

View File

@ -86,7 +86,7 @@
components: {}, components: {},
data () { data () {
return { return {
CONTEST_STATUS_REVERSE: CONTEST_STATUS_REVERSE, CONTEST_STATUS: CONTEST_STATUS,
route_name: '', route_name: '',
btnLoading: false, btnLoading: false,
contestID: '', contestID: '',
@ -164,7 +164,7 @@
), ),
countdownColor () { countdownColor () {
if (this.contestStatus) { if (this.contestStatus) {
return CONTEST_STATUS[this.contestStatus].color return CONTEST_STATUS_REVERSE[this.contestStatus].color
} }
} }
}, },

View File

@ -19,7 +19,7 @@
</li> </li>
<li> <li>
<Dropdown @on-click="onStatusChange"> <Dropdown @on-click="onStatusChange">
<span>{{query.status === '' ? 'Status' : CONTEST_STATUS[query.status].name}} <span>{{query.status === '' ? 'Status' : CONTEST_STATUS_REVERSE[query.status].name}}
<Icon type="arrow-down-b"></Icon> <Icon type="arrow-down-b"></Icon>
</span> </span>
<Dropdown-menu slot="list"> <Dropdown-menu slot="list">
@ -67,7 +67,7 @@
</ul> </ul>
</Col> </Col>
<Col :span="4" style="text-align: center"> <Col :span="4" style="text-align: center">
<Tag type="dot" :color="CONTEST_STATUS[contest.status].color">{{CONTEST_STATUS[contest.status].name}}</Tag> <Tag type="dot" :color="CONTEST_STATUS_REVERSE[contest.status].color">{{CONTEST_STATUS_REVERSE[contest.status].name}}</Tag>
</Col> </Col>
</Row> </Row>
</li> </li>
@ -83,9 +83,9 @@
import api from '@oj/api' import api from '@oj/api'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import utils from '@/utils/utils' import utils from '@/utils/utils'
import Pagination from '@/components/Pagination' import Pagination from '@/pages/oj/components/Pagination'
import time from '@/utils/time' import time from '@/utils/time'
import { CONTEST_STATUS, CONTEST_TYPE } from '@/utils/constants' import { CONTEST_STATUS_REVERSE, CONTEST_TYPE } from '@/utils/constants'
const limit = 4 const limit = 4
@ -106,7 +106,7 @@
total: 0, total: 0,
rows: '', rows: '',
contests: [], contests: [],
CONTEST_STATUS: CONTEST_STATUS, CONTEST_STATUS_REVERSE: CONTEST_STATUS_REVERSE,
// for password modal use // for password modal use
cur_contest_id: '' cur_contest_id: ''
} }

View File

@ -32,7 +32,7 @@
</template> </template>
<script> <script>
import moment from 'moment' import moment from 'moment'
import Pagination from '~/Pagination' import Pagination from '@oj/components/Pagination'
import { mapActions, mapState } from 'vuex' import { mapActions, mapState } from 'vuex'
import { types } from '@oj/store' import { types } from '@oj/store'

View File

@ -18,7 +18,7 @@
<script> <script>
import {mapState, mapGetters} from 'vuex' import {mapState, mapGetters} from 'vuex'
import {ProblemMixin} from '~/mixins' import {ProblemMixin} from '@oj/components/mixins'
export default { export default {
name: 'ContestProblemList', name: 'ContestProblemList',

View File

@ -31,7 +31,7 @@
</Panel> </Panel>
</template> </template>
<script> <script>
import Pagination from '~/Pagination' import Pagination from '@oj/components/Pagination'
import { mapActions, mapState } from 'vuex' import { mapActions, mapState } from 'vuex'
import { types } from '@oj/store' import { types } from '@oj/store'

View File

@ -40,7 +40,7 @@
<script> <script>
import api from '@oj/api' import api from '@oj/api'
import Pagination from '~/Pagination' import Pagination from '@oj/components/Pagination'
export default { export default {
name: 'Announcement', name: 'Announcement',

Some files were not shown because too many files have changed in this diff Show More