This commit is contained in:
ZaneYork 2020-10-22 15:35:23 +08:00
commit e04c3c364f
25 changed files with 13514 additions and 0 deletions

29
.babelrc Normal file
View File

@ -0,0 +1,29 @@
{
"presets": [
[
"env",
{
"modules": false,
"targets": {
"browsers": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
}
],
"stage-2"
],
"plugins": [
"transform-vue-jsx",
"transform-runtime",
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}

9
.editorconfig Normal file
View File

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

14
.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
.DS_Store
node_modules/
/dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln

10
.postcssrc.js Normal file
View File

@ -0,0 +1,10 @@
// https://github.com/michael-ciniawsky/postcss-load-config
module.exports = {
"plugins": {
"postcss-import": {},
"postcss-url": {},
// to edit target browsers: use "browserslist" field in package.json
"autoprefixer": {}
}
}

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# vkconfig
> A Vue.js project
## Build Setup
``` bash
# install dependencies
npm install
# serve with hot reload at localhost:8080
npm run dev
# build for production with minification
npm run build
# build for production and view the bundle analyzer report
npm run build --report
```
For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).

41
build/build.js Normal file
View File

@ -0,0 +1,41 @@
'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, (err, stats) => {
spinner.stop()
if (err) throw err
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
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'
))
})
})

54
build/check-versions.js Normal file
View File

@ -0,0 +1,54 @@
'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)
}
}

BIN
build/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

106
build/utils.js Normal file
View File

@ -0,0 +1,106 @@
'use strict'
const path = require('path')
const config = require('../config')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const packageConfig = require('../package.json')
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: {
sourceMap: options.sourceMap
}
}
const postcssLoader = {
loader: 'postcss-loader',
options: {
sourceMap: options.sourceMap
}
}
const px2remLoader = {
loader: 'px2rem-loader',
options: {
remUnit: 75 // (这里是指设计稿的宽度为 750 / 10)
}
}
// generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) {
const loaders = options.usePostCSS ? [cssLoader, postcssLoader, px2remLoader] : [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
}
exports.createNotifierCallback = () => {
const notifier = require('node-notifier')
return (severity, errors) => {
if (severity !== 'error') return
const error = errors[0]
const filename = error.file && error.file.split('!').pop()
notifier.notify({
title: packageConfig.name,
message: severity + ': ' + error.name,
subtitle: filename || '',
icon: path.join(__dirname, 'logo.png')
})
}
}

22
build/vue-loader.conf.js Normal file
View File

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

View File

@ -0,0 +1,84 @@
'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 = {
context: path.resolve(__dirname, '../'),
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: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
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,
outputPath: utils.assetsPath('fonts'),//决定打包出来的文件的路径 在 dist 下的路径
publicPath:'../fonts/',
name:'[name].[ext]'
}
}
]
},
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
}

95
build/webpack.dev.conf.js Normal file
View File

@ -0,0 +1,95 @@
'use strict'
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const path = require('path')
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const portfinder = require('portfinder')
const HOST = process.env.HOST
const PORT = process.env.PORT && Number(process.env.PORT)
const devWebpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
},
// cheap-module-eval-source-map is faster for development
devtool: config.dev.devtool,
// these devServer options should be customized in /config/index.js
devServer: {
clientLogLevel: 'warning',
historyApiFallback: {
rewrites: [
{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
],
},
hot: true,
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: config.dev.errorOverlay
? { warnings: false, errors: true }
: false,
publicPath: config.dev.assetsPublicPath,
proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
poll: config.dev.poll,
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/dev.env')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
}),
// copy custom static assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.dev.assetsSubDirectory,
ignore: ['.*']
}
])
]
})
module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || config.dev.port
portfinder.getPort((err, port) => {
if (err) {
reject(err)
} else {
// publish the new Port, necessary for e2e tests
process.env.PORT = port
// add port to devServer config
devWebpackConfig.devServer.port = port
// Add FriendlyErrorsPlugin
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
},
onErrors: config.dev.notifyOnErrors
? utils.createNotifierCallback()
: undefined
}))
resolve(devWebpackConfig)
}
})
})

145
build/webpack.prod.conf.js Normal file
View File

@ -0,0 +1,145 @@
'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 UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const env = require('../config/prod.env')
const webpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({
sourceMap: config.build.productionSourceMap,
extract: true,
usePostCSS: true
})
},
devtool: config.build.productionSourceMap ? config.build.devtool : false,
output: {
path: config.build.assetsRoot,
filename: utils.assetsPath('js/[name].js'),
chunkFilename: utils.assetsPath('js/[id].js')
},
plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({
'process.env': env
}),
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false
}
},
sourceMap: config.build.productionSourceMap,
parallel: true
}),
// extract css into its own file
new ExtractTextPlugin({
filename: utils.assetsPath('css/[name].css'),
// Setting the following option to `false` will not extract CSS from codesplit chunks.
// Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
// It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
// increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
allChunks: true,
}),
// Compress extracted CSS. We are using this plugin so that possible
// duplicated CSS from different components can be deduped.
new OptimizeCSSPlugin({
cssProcessorOptions: config.build.productionSourceMap
? { safe: true, map: { inline: false } }
: { 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 vendor modules does not change
new webpack.HashedModuleIdsPlugin(),
// enable scope hoisting
new webpack.optimize.ModuleConcatenationPlugin(),
// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks (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',
minChunks: Infinity
}),
// This instance extracts shared chunks from code splitted chunks and bundles them
// in a separate chunk, similar to the vendor chunk
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
new webpack.optimize.CommonsChunkPlugin({
name: 'app',
async: 'vendor-async',
children: true,
minChunks: 3
}),
// 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

7
config/dev.env.js Normal file
View File

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

69
config/index.js Normal file
View File

@ -0,0 +1,69 @@
'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path')
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '',
proxyTable: {},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // 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
},
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '',
/**
* Source Maps
*/
productionSourceMap: false,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
// 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
}
}

4
config/prod.env.js Normal file
View File

@ -0,0 +1,4 @@
'use strict'
module.exports = {
NODE_ENV: '"production"'
}

22
index.html Normal file
View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Virtual Keyboard Config Editor</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
<script>
window.getJsonCallback = null;
window.webObject = { getText: function(){ return '{"vToggle":{"key":"None","rectangle":{"X":36,"Y":12,"Width":64,"Height":64},"autoHidden":false},"buttons":[{"key":"Q","rectangle":{"X":200,"Y":80,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"I","rectangle":{"X":363,"Y":80,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"P","rectangle":{"X":526,"Y":80,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"B","rectangle":{"X":1180,"Y":12,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null}],"buttonsExtend":[{"key":"F1","rectangle":{"X":190,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"F2","rectangle":{"X":290,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"F3","rectangle":{"X":390,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"H","rectangle":{"X":490,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"O","rectangle":{"X":590,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"K","rectangle":{"X":690,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"U","rectangle":{"X":790,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"M","rectangle":{"X":890,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"V","rectangle":{"X":990,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"RightWindows","rectangle":{"X":1090,"Y":170,"Width":90,"Height":90},"transparency":0.5,"alias":"CMD","command":null},{"key":"S","rectangle":{"X":1080,"Y":12,"Width":90,"Height":90},"transparency":0.5,"alias":null,"command":null},{"key":"None","rectangle":{"X":980,"Y":12,"Width":90,"Height":90},"transparency":0.5,"alias":"Zoom","command":"zoom"}]}'; }, getMode: function(){ return 'tree';}, getLanguage: function(){ return 'zh-CN';}, isEditable: function(){ return true;}, getHeight: function(){ return 720;}, getWidth: function(){ return 1280;}, };
window.getJson = function()
{
if(window.getJsonCallback != null) {
window.webObject.setText(JSON.stringify(window.getJsonCallback()));
}
}
</script>
</body>
</html>

12090
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

73
package.json Normal file
View File

@ -0,0 +1,73 @@
{
"name": "vkconfig",
"version": "1.0.0",
"description": "A Vue.js project",
"author": "ZaneYork <ZaneYork@qq.com>",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"build": "node build/build.js"
},
"dependencies": {
"element-ui": "^2.13.2",
"konva": "^7.1.4",
"uuid": "^8.3.1",
"vant": "^2.10.10",
"vue": "^2.5.2",
"vue-draggable-float": "0.0.4",
"vue-draggable-resizable": "^2.2.0",
"vue-i18n": "^8.22.1",
"vue-konva": "^2.1.6"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-component": "^1.1.1",
"babel-plugin-import": "^1.13.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"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",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"prettier": "^1.12.1",
"px2rem-loader": "^0.1.9",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}

19
src/App.vue Normal file
View File

@ -0,0 +1,19 @@
<template>
<div id="app">
<VirtualKeyboard/>
</div>
</template>
<script>
import VirtualKeyboard from './components/VirtualKeyboard'
export default {
name: 'App',
components: {
VirtualKeyboard
}
}
</script>
<style>
</style>

BIN
src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -0,0 +1,521 @@
<template>
<div>
<div :grid='grid' @click="onParentClick"
:style="{height: height+'px', width: width + 'px',
border: '1px solid #13a8d5', position: 'relative',
transform: 'scale(' + scale +')', 'transform-origin': '0 0',
'margin-bottom': '-' + height*(1-scale) + 'px'}">
<vue-draggable-resizable :parent="true" className="vdr button button-vtg"
@dragging="(x,y)=>onDrag(config.vToggle,x,y)" :resizable="false" :scale="scale"
@resizing="(x, y, width, height)=>onResize(config.vToggle,x, y, width, height)"
:w="config.vToggle.rectangle.Width"
:h="config.vToggle.rectangle.Height"
:x="config.vToggle.rectangle.X"
:y="config.vToggle.rectangle.Y">
<p class="button-text" @click="toggle">{{$t('toggle')}}</p>
</vue-draggable-resizable>
<vue-draggable-resizable v-for="button in config.buttons" :key="firstNotEmpty(button.id, button.key)"
:parent="true" className="vdr button" :resizable="false" :scale="scale"
@dragging="(x,y)=>onDrag(button,x,y)"
@resizing="(x, y, width, height)=>onResize(button,x, y, width, height)"
@activated="()=>onActivated(button)"
:w="button.rectangle.Width"
:h="button.rectangle.Height"
:x="button.rectangle.X"
:y="button.rectangle.Y">
<p class="button-text">{{firstNotEmpty(button.alias, button.key)}}</p>
</vue-draggable-resizable>
<vue-draggable-resizable v-for="button in config.buttonsExtend" :key="firstNotEmpty(button.id, button.key)"
:parent="true" className="vdr button button-ext" v-if="toggleState" :resizable="false" :scale="scale"
@dragging="(x,y)=>onDrag(button,x,y)"
@resizing="(x, y, width, height)=>onResize(button,x, y, width, height)"
@activated="()=>onActivated(button)"
:w="button.rectangle.Width"
:h="button.rectangle.Height"
:x="button.rectangle.X"
:y="button.rectangle.Y">
<p class="button-text">{{firstNotEmpty(button.alias, button.key)}}</p>
</vue-draggable-resizable>
</div>
<el-drawer
title=""
:visible.sync="drawer"
:direction="rtl"
size="40%"
:wrapperClosable="false"
:show-close="true"
:with-header="true">
<el-form ref="form" label-width="50px">
<el-form-item :label="$t('X')">
<el-slider
v-model="currentButton.rectangle.X"
:max="width" :min="0" :step="5"
show-input>
</el-slider>
</el-form-item>
<el-form-item :label="$t('Y')">
<el-slider
v-model="currentButton.rectangle.Y"
:max="height" :min="0" :step="5"
show-input>
</el-slider>
</el-form-item>
<el-form-item :label="$t('Width')">
<el-slider
v-model="currentButton.rectangle.Width"
:max="width" :min="5" :step="5"
show-input>
</el-slider>
</el-form-item>
<el-form-item :label="$t('Height')">
<el-slider
v-model="currentButton.rectangle.Height"
:max="height" :min="5" :step="5"
show-input>
</el-slider>
</el-form-item>
</el-form>
</el-drawer>
<draggable
:distanceRight='0'
:distanceBottom='100'
:isScrollHidden='false'
:isCanDraggable='true'
:zIndex="100">
<el-button type="primary" icon="el-icon-edit" circle @click="drawer=true"></el-button>
</draggable>
<el-form ref="form" label-width="80px">
<el-form-item :label="$t('key')">
<el-select v-model="currentButton.key" filterable :placeholder="$t('key')">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('alias')">
<el-col :span="10">
<el-input v-model="currentButton.alias" :placeholder="$t('alias')"></el-input>
</el-col>
</el-form-item>
<el-form-item :label="$t('command')">
<el-col :span="10">
<el-input v-model="currentButton.command" :placeholder="$t('command')"></el-input>
</el-col>
</el-form-item>
<el-form-item :label="$t('transparency')">
<el-row>
<el-col :span="2">
<el-color-picker v-model="color" show-alpha disabled></el-color-picker>
</el-col>
<el-col :span="22">
<el-slider
v-model="currentButton.transparency"
:max="1" :min="0" :step="0.01"
show-input>
</el-slider>
</el-col>
</el-row>
</el-form-item>
<el-form-item :label="$t('X')">
<el-slider
v-model="currentButton.rectangle.X"
:max="width" :min="0" :step="5"
show-input>
</el-slider>
</el-form-item>
<el-form-item :label="$t('Y')">
<el-slider
v-model="currentButton.rectangle.Y"
:max="height" :min="0" :step="5"
show-input>
</el-slider>
</el-form-item>
<el-form-item :label="$t('Width')">
<el-slider
v-model="currentButton.rectangle.Width"
:max="width" :min="5" :step="5"
show-input>
</el-slider>
</el-form-item>
<el-form-item :label="$t('Height')">
<el-slider
v-model="currentButton.rectangle.Height"
:max="height" :min="5" :step="5"
show-input>
</el-slider>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onAddButton">{{$t('add')}}</el-button>
<el-button type="danger" @click="onRemoveButton">{{$t('remove')}}</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
import {v4 as uuidv4} from 'uuid';
import Draggable from 'vue-draggable-float'
export default {
components:{Draggable},
data: function () {
return {
grid: [5, 5],
scale: 0.4,
width: 1280,
height: 720,
toggleState: true,
drawer: false,
currentButton: {
key: '',
alias: '',
command: '',
rectangle: {X: 0, Y: 0, Width: 90, Height: 90},
transparency: 0.5
},
options: [
{label: "None", value: "None"},
{label: "MouseLeft", value: "MouseLeft"},
{label: "MouseRight", value: "MouseRight"},
{label: "MouseMiddle", value: "MouseMiddle"},
{label: "MouseX1", value: "MouseX1"},
{label: "MouseX2", value: "MouseX2"},
{label: "ControllerA", value: "ControllerA"},
{label: "ControllerB", value: "ControllerB"},
{label: "ControllerX", value: "ControllerX"},
{label: "ControllerY", value: "ControllerY"},
{label: "ControllerBack", value: "ControllerBack"},
{label: "ControllerStart", value: "ControllerStart"},
{label: "DPadUp", value: "DPadUp"},
{label: "DPadDown", value: "DPadDown"},
{label: "DPadLeft", value: "DPadLeft"},
{label: "DPadRight", value: "DPadRight"},
{label: "LeftShoulder", value: "LeftShoulder"},
{label: "RightShoulder", value: "RightShoulder"},
{label: "LeftTrigger", value: "LeftTrigger"},
{label: "RightTrigger", value: "RightTrigger"},
{label: "LeftStick", value: "LeftStick"},
{label: "RightStick", value: "RightStick"},
{label: "BigButton", value: "BigButton"},
{label: "LeftThumbstickLeft", value: "LeftThumbstickLeft"},
{label: "LeftThumbstickRight", value: "LeftThumbstickRight"},
{label: "LeftThumbstickDown", value: "LeftThumbstickDown"},
{label: "LeftThumbstickUp", value: "LeftThumbstickUp"},
{label: "RightThumbstickLeft", value: "RightThumbstickLeft"},
{label: "RightThumbstickRight", value: "RightThumbstickRight"},
{label: "RightThumbstickDown", value: "RightThumbstickDown"},
{label: "RightThumbstickUp", value: "RightThumbstickUp"},
{label: "A", value: "A"},
{label: "Add", value: "Add"},
{label: "Apps", value: "Apps"},
{label: "Attn", value: "Attn"},
{label: "B", value: "B"},
{label: "Back", value: "Back"},
{label: "BrowserBack", value: "BrowserBack"},
{label: "BrowserFavorites", value: "BrowserFavorites"},
{label: "BrowserForward", value: "BrowserForward"},
{label: "BrowserHome", value: "BrowserHome"},
{label: "BrowserRefresh", value: "BrowserRefresh"},
{label: "BrowserSearch", value: "BrowserSearch"},
{label: "BrowserStop", value: "BrowserStop"},
{label: "C", value: "C"},
{label: "CapsLock", value: "CapsLock"},
{label: "ChatPadGreen", value: "ChatPadGreen"},
{label: "ChatPadOrange", value: "ChatPadOrange"},
{label: "Crsel", value: "Crsel"},
{label: "D", value: "D"},
{label: "D0", value: "D0"},
{label: "D1", value: "D1"},
{label: "D2", value: "D2"},
{label: "D3", value: "D3"},
{label: "D4", value: "D4"},
{label: "D5", value: "D5"},
{label: "D6", value: "D6"},
{label: "D7", value: "D7"},
{label: "D8", value: "D8"},
{label: "D9", value: "D9"},
{label: "Decimal", value: "Decimal"},
{label: "Delete", value: "Delete"},
{label: "Divide", value: "Divide"},
{label: "Down", value: "Down"},
{label: "E", value: "E"},
{label: "End", value: "End"},
{label: "Enter", value: "Enter"},
{label: "EraseEof", value: "EraseEof"},
{label: "Escape", value: "Escape"},
{label: "Execute", value: "Execute"},
{label: "Exsel", value: "Exsel"},
{label: "F", value: "F"},
{label: "F1", value: "F1"},
{label: "F10", value: "F10"},
{label: "F11", value: "F11"},
{label: "F12", value: "F12"},
{label: "F13", value: "F13"},
{label: "F14", value: "F14"},
{label: "F15", value: "F15"},
{label: "F16", value: "F16"},
{label: "F17", value: "F17"},
{label: "F18", value: "F18"},
{label: "F19", value: "F19"},
{label: "F2", value: "F2"},
{label: "F20", value: "F20"},
{label: "F21", value: "F21"},
{label: "F22", value: "F22"},
{label: "F23", value: "F23"},
{label: "F24", value: "F24"},
{label: "F3", value: "F3"},
{label: "F4", value: "F4"},
{label: "F5", value: "F5"},
{label: "F6", value: "F6"},
{label: "F7", value: "F7"},
{label: "F8", value: "F8"},
{label: "F9", value: "F9"},
{label: "G", value: "G"},
{label: "H", value: "H"},
{label: "Help", value: "Help"},
{label: "Home", value: "Home"},
{label: "I", value: "I"},
{label: "ImeConvert", value: "ImeConvert"},
{label: "ImeNoConvert", value: "ImeNoConvert"},
{label: "Insert", value: "Insert"},
{label: "J", value: "J"},
{label: "K", value: "K"},
{label: "Kana", value: "Kana"},
{label: "Kanji", value: "Kanji"},
{label: "L", value: "L"},
{label: "LaunchApplication1", value: "LaunchApplication1"},
{label: "LaunchApplication2", value: "LaunchApplication2"},
{label: "LaunchMail", value: "LaunchMail"},
{label: "Left", value: "Left"},
{label: "LeftAlt", value: "LeftAlt"},
{label: "LeftControl", value: "LeftControl"},
{label: "LeftShift", value: "LeftShift"},
{label: "LeftWindows", value: "LeftWindows"},
{label: "M", value: "M"},
{label: "MediaNextTrack", value: "MediaNextTrack"},
{label: "MediaPlayPause", value: "MediaPlayPause"},
{label: "MediaPreviousTrack", value: "MediaPreviousTrack"},
{label: "MediaStop", value: "MediaStop"},
{label: "Multiply", value: "Multiply"},
{label: "N", value: "N"},
{label: "NumLock", value: "NumLock"},
{label: "NumPad0", value: "NumPad0"},
{label: "NumPad1", value: "NumPad1"},
{label: "NumPad2", value: "NumPad2"},
{label: "NumPad3", value: "NumPad3"},
{label: "NumPad4", value: "NumPad4"},
{label: "NumPad5", value: "NumPad5"},
{label: "NumPad6", value: "NumPad6"},
{label: "NumPad7", value: "NumPad7"},
{label: "NumPad8", value: "NumPad8"},
{label: "NumPad9", value: "NumPad9"},
{label: "O", value: "O"},
{label: "Oem8", value: "Oem8"},
{label: "OemAuto", value: "OemAuto"},
{label: "OemBackslash", value: "OemBackslash"},
{label: "OemClear", value: "OemClear"},
{label: "OemCloseBrackets", value: "OemCloseBrackets"},
{label: "OemComma", value: "OemComma"},
{label: "OemCopy", value: "OemCopy"},
{label: "OemEnlW", value: "OemEnlW"},
{label: "OemMinus", value: "OemMinus"},
{label: "OemOpenBrackets", value: "OemOpenBrackets"},
{label: "OemPeriod", value: "OemPeriod"},
{label: "OemPipe", value: "OemPipe"},
{label: "OemPlus", value: "OemPlus"},
{label: "OemQuestion", value: "OemQuestion"},
{label: "OemQuotes", value: "OemQuotes"},
{label: "OemSemicolon", value: "OemSemicolon"},
{label: "OemTilde", value: "OemTilde"},
{label: "P", value: "P"},
{label: "Pa1", value: "Pa1"},
{label: "PageDown", value: "PageDown"},
{label: "PageUp", value: "PageUp"},
{label: "Pause", value: "Pause"},
{label: "Play", value: "Play"},
{label: "Print", value: "Print"},
{label: "PrintScreen", value: "PrintScreen"},
{label: "ProcessKey", value: "ProcessKey"},
{label: "Q", value: "Q"},
{label: "R", value: "R"},
{label: "Right", value: "Right"},
{label: "RightAlt", value: "RightAlt"},
{label: "RightControl", value: "RightControl"},
{label: "RightShift", value: "RightShift"},
{label: "RightWindows", value: "RightWindows"},
{label: "S", value: "S"},
{label: "Scroll", value: "Scroll"},
{label: "Select", value: "Select"},
{label: "SelectMedia", value: "SelectMedia"},
{label: "Separator", value: "Separator"},
{label: "Sleep", value: "Sleep"},
{label: "Space", value: "Space"},
{label: "Subtract", value: "Subtract"},
{label: "T", value: "T"},
{label: "Tab", value: "Tab"},
{label: "U", value: "U"},
{label: "Up", value: "Up"},
{label: "V", value: "V"},
{label: "VolumeDown", value: "VolumeDown"},
{label: "VolumeMute", value: "VolumeMute"},
{label: "VolumeUp", value: "VolumeUp"},
{label: "W", value: "W"},
{label: "X", value: "X"},
{label: "Y", value: "Y"},
{label: "Z", value: "Z"},
{label: "Zoom", value: "Zoom"},
],
config: {}
}
},
computed: {
color: function () {
return 'rgba(255,171,0,' + this.currentButton.transparency + ')';
}
},
mounted() {
this.$i18n.locale = window.webObject.getLanguage();
this.width = window.webObject.getWidth();
this.height = window.webObject.getHeight();
window.setJson = (json) => {
let config = JSON.parse(json);
for (let button of config.buttons) {
button.id = uuidv4();
}
for (let button of config.buttonsExtend) {
button.id = uuidv4();
}
this.config = config;
};
window.setJson(window.webObject.getText());
window.getJsonCallback = () => {
return this.config;
};
},
methods: {
toggle: function () {
this.toggleState = !this.toggleState;
},
onResize: function (button, x, y, width, height) {
button.rectangle.X = x
button.rectangle.Y = y
button.rectangle.Width = width
button.rectangle.Height = height
},
onDrag: function (button, x, y) {
button.rectangle.X = x
button.rectangle.Y = y
},
onActivated: function (button) {
this.currentButton = button;
},
onParentClick: function (event) {
let dx = event.clientX / this.scale - (this.currentButton.rectangle.X + this.currentButton.rectangle.Width / 2);
let dy = event.clientY / this.scale - (this.currentButton.rectangle.Y + this.currentButton.rectangle.Height / 2);
let adx = Math.abs(dx);
let ady = Math.abs(dy);
if (adx > ady) {
if (adx < this.currentButton.rectangle.Width / 2) {
return;
}
debugger
if (dx > 0) {
this.currentButton.rectangle.X += this.grid[0];
} else {
this.currentButton.rectangle.X -= this.grid[0];
}
} else {
if (ady < this.currentButton.rectangle.Height / 2) {
return;
}
debugger
if (dy > 0) {
this.currentButton.rectangle.Y += this.grid[1];
} else {
this.currentButton.rectangle.Y -= this.grid[1];
}
}
},
onAddButton: function () {
let target;
if (!this.toggleState) {
target = this.config.buttons;
} else {
target = this.config.buttonsExtend;
}
let newButton = {
"id": uuidv4(),
"key": this.firstNotEmpty(this.currentButton.key, "None"),
"rectangle": {
"X": this.currentButton.rectangle.X,
"Y": this.currentButton.rectangle.Y,
"Width": this.currentButton.rectangle.Width,
"Height": this.currentButton.rectangle.Height
},
"transparency": this.currentButton.transparency,
"alias": this.currentButton.alias,
"command": this.currentButton.command
}
target.push(newButton);
this.currentButton = newButton;
},
onRemoveButton: function () {
let list = this.config.buttons;
let id = this.firstNotEmpty(this.currentButton.id, this.currentButton.key);
let index = list.findIndex(button => {
if (this.firstNotEmpty(button.id, button.key) === id) {
return true
}
});
if (index < 0) {
list = this.config.buttonsExtend;
index = list.findIndex(button => {
if (this.firstNotEmpty(button.id, button.key) === id) {
return true
}
});
}
if (index >= 0)
list.splice(index, 1);
},
firstNotEmpty: function (alias, key) {
return this.isEmpty(alias) ? key : alias;
},
//
isEmpty: function (obj) {
return typeof obj == "undefined" || obj == null || obj === "";
}
}
}
</script>
<style scoped>
.button-text {
font-size: medium
}
.vdr {
display: flex;
justify-content: center;
align-items: center;
}
.button {
background-color: darkorange;
}
.button.active {
border-color: deepskyblue;
border-width: thick;
}
.button-vtg {
background-color: lightyellow;
}
.button-ext {
background-color: lightgoldenrodyellow;
}
</style>

27
src/i18n/messages.js Normal file
View File

@ -0,0 +1,27 @@
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
const messages = {
en: {
toggle: "Toggle",
add: "ADD",
remove: "REMOVE",
key: "Key",
alias: "Alias",
command: "Command",
transparency: "Transparency",
...enLocale
},
zh: {
toggle: "切换",
add: "新增",
remove: "移除",
key: "按键",
alias: "别名",
command: "命令",
transparency: "透明度",
...zhLocale
}
}
export default messages;

52
src/main.js Normal file
View File

@ -0,0 +1,52 @@
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import VueI18n from 'vue-i18n'
import messages from "./i18n/messages";
import VueDraggableResizable from 'vue-draggable-resizable'
import { Row, Col, Button, Select, Option, Input, InputNumber, Slider, ColorPicker, Form, FormItem, Drawer } from 'element-ui';
import ElementLocale from 'element-ui/lib/locale'
import VueKonva from 'vue-konva'
// optionally import default styles
import 'vue-draggable-resizable/dist/VueDraggableResizable.css'
// register component to use
Vue.config.productionTip = false
Vue.use(VueI18n)
Vue.use(VueKonva)
Vue.component('vue-draggable-resizable', VueDraggableResizable)
Vue.component(Row.name, Row, );
Vue.component(Col.name, Col);
Vue.component(Button.name, Button);
Vue.component(Select.name, Select);
Vue.component(Option.name, Option);
Vue.component(Input.name, Input);
Vue.component(InputNumber.name, InputNumber);
Vue.component(Slider.name, Slider);
Vue.component(ColorPicker.name, ColorPicker);
Vue.component(Form.name, Form);
Vue.component(FormItem.name, FormItem);
Vue.component(Drawer.name, Drawer);
ElementLocale.i18n((key, value) => i18n.t(key, value))
const i18n = new VueI18n({
locale: navigator.language, // set locale
messages, // set locale messages
})
window.onresize = setHtmlFontSize;
function setHtmlFontSize(){
const htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
const htmlDom = document.getElementsByTagName('html')[0];
htmlDom.style.fontSize = htmlWidth / 10 + 'px';
};
setHtmlFontSize();
/* eslint-disable no-new */
new Vue({
i18n,
el: '#app',
components: { App },
template: '<App/>'
})

0
static/.gitkeep Normal file
View File