├── .babelrc ├── .editorconfig ├── .gitignore ├── .postcssrc.js ├── .slugignore ├── .travis.yml ├── README.md ├── build ├── build.js ├── check-versions.js ├── dev-client.js ├── dev-server.js ├── utils.js ├── vue-loader.conf.js ├── webpack.base.conf.js ├── webpack.dev.conf.js ├── webpack.prod.conf.js └── webpack.publish.conf.js ├── config ├── db.js ├── dev.env.js ├── index.js └── prod.env.js ├── docs ├── 功能.xmind └── 结构.xmind ├── env.sample ├── index.html ├── index.js ├── migrations └── 201706161508_add_avatar_field_to_users.js ├── package.json ├── public └── 3 │ ├── index.html │ ├── preview.2ffd299d.js │ ├── preview.2ffd299d.js.map │ ├── preview.5c6ac4be.js │ ├── preview.5c6ac4be.js.map │ ├── preview.627d0d64.js │ ├── preview.627d0d64.js.map │ ├── preview.f6480c81.js │ ├── preview.f6480c81.js.map │ ├── vendor.0ae739aa.js │ ├── vendor.0ae739aa.js.map │ ├── vendor.664ca3cb.js │ ├── vendor.664ca3cb.js.map │ ├── vendor.88e1cfca.js │ ├── vendor.88e1cfca.js.map │ ├── vendor.d777f03f.js │ └── vendor.d777f03f.js.map ├── screen.png ├── server ├── constants.js ├── controllers │ ├── changelogs.js │ ├── count.js │ ├── files.js │ ├── page.js │ ├── pages.js │ ├── publish.js │ └── users.js ├── index.js ├── lib │ ├── api.js │ ├── errorlog.js │ ├── passport.js │ └── publish │ │ ├── index.js │ │ ├── opads.js │ │ └── qiniu.js ├── models │ ├── changelog.js │ ├── index.js │ ├── pages.js │ └── users.js └── views │ └── activity.ejs ├── src ├── App.vue ├── api │ └── index.js ├── app.js ├── assets │ └── img │ │ ├── phone-head.png │ │ └── piper_logo.svg ├── components │ ├── ProgressBar.vue │ ├── countdown.vue │ ├── ctrl-bar.vue │ ├── drag-drop.vue │ ├── drag-move.vue │ ├── header.vue │ ├── index.js │ ├── loading.vue │ ├── module-container.vue │ ├── preview.vue │ ├── property.vue │ ├── qrcode.vue │ ├── render.vue │ └── swiper │ │ ├── index.vue │ │ ├── swiper-item.vue │ │ └── swiper.js ├── constants │ ├── default.js │ ├── lang.js │ ├── props.js │ └── rules.js ├── filters │ └── index.js ├── modules │ ├── btn.vue │ ├── countdown.vue │ ├── index.js │ ├── poster.vue │ ├── relative.vue │ ├── swipe.vue │ └── txt.vue ├── preview.js ├── property │ ├── common.js │ ├── group.vue │ ├── html-style.vue │ ├── index.js │ ├── input-checkbox.vue │ ├── input-color.vue │ ├── input-date.vue │ ├── input-font.vue │ ├── input-image.vue │ ├── input-number.vue │ ├── input-radio.vue │ ├── input-text.vue │ ├── input-textarea.vue │ ├── input-wheel.vue │ └── input.js ├── router │ └── index.js ├── skin │ ├── _base.less │ ├── _variable.less │ └── dpi.less ├── store │ ├── actions.js │ ├── getters.js │ ├── index.js │ ├── modules │ │ ├── base.js │ │ └── render.js │ └── mutation-types.js ├── utils │ └── index.js └── views │ ├── Changelog.vue │ ├── Designer.vue │ ├── Home.vue │ ├── Layout.vue │ ├── Login.vue │ ├── PageList.vue │ ├── Preview.vue │ └── Users.vue ├── static └── .gitKeep └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "targets": { 5 | "node": true, 6 | "uglify": true 7 | } 8 | }], 9 | "stage-2" 10 | ], 11 | "plugins": ["transform-runtime", "transform-decorators-legacy"], 12 | "comments": false, 13 | "env": { 14 | "test": { 15 | "presets": ["env", "stage-2"], 16 | "plugins": [ "istanbul" ] 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | .DS_Store 4 | /dist 5 | .idea 6 | public/* 7 | .vscode 8 | now.json 9 | .env 10 | .env.now 11 | -------------------------------------------------------------------------------- /.postcssrc.js: -------------------------------------------------------------------------------- 1 | // https://github.com/michael-ciniawsky/postcss-load-config 2 | 3 | module.exports = { 4 | "plugins": { 5 | // to edit target browsers: use "browserlist" field in package.json 6 | "autoprefixer": {} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.slugignore: -------------------------------------------------------------------------------- 1 | yarn.lock 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: enabled 2 | dist: trusty 3 | language: node_js 4 | node_js: 5 | - stable 6 | - "8" 7 | - "7" 8 | before_install: 9 | - export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH 10 | - export DISPLAY=:99.0 11 | - sh -e /etc/init.d/xvfb start 12 | - npm i -g npm@^5.3.0 13 | - npm config set spin false 14 | install: 15 | - npm install 16 | cache: 17 | directories: 18 | - node_modules 19 | after_script: 20 | - npm run build 21 | - npm run start 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Piper [![Build Status](https://travis-ci.org/fireyy/piper.svg?branch=dev)](https://travis-ci.org/fireyy/piper) 2 | 3 |

4 | 5 | 6 |
7 | Live Demo 8 |
9 |

10 | 11 | > A drag-and-drop mobile website builder base on Vue. 12 | 13 | ### Install 14 | 15 | ```shell 16 | npm install 17 | ``` 18 | 19 | ### Config 20 | 21 | First of all,create a database `piper` in `PostgreSQL`, `MySQL`, `SQLite` or `MSSQL`. 22 | 23 | Then set up `.env` file with your: 24 | 25 | - Database connection details 26 | - Qiniu SDK config 27 | - Github `CLIENT_ID` and `CLIENT_SECRET` 28 | 29 | ```shell 30 | cp env.sample .env 31 | ``` 32 | 33 | ### Develop 34 | 35 | ```shell 36 | npm run dev 37 | ``` 38 | 39 | ### A message about px to rem 40 | 41 | ```css 42 | // `px` is converted to `rem` 43 | .convert { 44 | font-size: 16px; // converted to 1rem 45 | } 46 | 47 | // `Px` or `PX` is ignored by `postcss-pxtorem` but still accepted by browsers 48 | .ignore { 49 | border: 1Px solid; // ignored 50 | border-width: 2PX; // ignored 51 | } 52 | ``` 53 | 54 | ### Changelog 55 | 56 | #### 1.0.5 57 | 58 | - Login with Github base on [Passport.js](http://passportjs.org/). 59 | - Use [Sequelize.js](http://docs.sequelizejs.com/) for Database dialects. 60 | - Use [Axios](https://github.com/mzabriskie/axios) instead of vue-resource. 61 | - fix issues. 62 | -------------------------------------------------------------------------------- /build/build.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | process.env.NODE_ENV = 'production' 4 | 5 | var ora = require('ora') 6 | var rm = require('rimraf') 7 | var path = require('path') 8 | var chalk = require('chalk') 9 | var webpack = require('webpack') 10 | var config = require('../config') 11 | var webpackConfig = require('./webpack.prod.conf') 12 | 13 | var spinner = ora('building for production...') 14 | spinner.start() 15 | 16 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { 17 | if (err) throw err 18 | webpack(webpackConfig, function (err, stats) { 19 | spinner.stop() 20 | if (err) throw err 21 | process.stdout.write(stats.toString({ 22 | colors: true, 23 | modules: false, 24 | children: false, 25 | chunks: false, 26 | chunkModules: false 27 | }) + '\n\n') 28 | 29 | console.log(chalk.cyan(' Build complete.\n')) 30 | console.log(chalk.yellow( 31 | ' Tip: built files are meant to be served over an HTTP server.\n' + 32 | ' Opening index.html over file:// won\'t work.\n' 33 | )) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /build/check-versions.js: -------------------------------------------------------------------------------- 1 | var chalk = require('chalk') 2 | var semver = require('semver') 3 | var packageConfig = require('../package.json') 4 | 5 | function exec (cmd) { 6 | return require('child_process').execSync(cmd).toString().trim() 7 | } 8 | 9 | var versionRequirements = [ 10 | { 11 | name: 'node', 12 | currentVersion: semver.clean(process.version), 13 | versionRequirement: packageConfig.engines.node 14 | }, 15 | { 16 | name: 'npm', 17 | currentVersion: exec('npm --version'), 18 | versionRequirement: packageConfig.engines.npm 19 | } 20 | ] 21 | 22 | module.exports = function () { 23 | var warnings = [] 24 | for (var i = 0; i < versionRequirements.length; i++) { 25 | var mod = versionRequirements[i] 26 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) { 27 | warnings.push(mod.name + ': ' + 28 | chalk.red(mod.currentVersion) + ' should be ' + 29 | chalk.green(mod.versionRequirement) 30 | ) 31 | } 32 | } 33 | 34 | if (warnings.length) { 35 | console.log('') 36 | console.log(chalk.yellow('To use this project, you must update following to modules:')) 37 | console.log() 38 | for (var i = 0; i < warnings.length; i++) { 39 | var warning = warnings[i] 40 | console.log(' ' + warning) 41 | } 42 | console.log() 43 | process.exit(1) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /build/dev-client.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | require('eventsource-polyfill') 3 | var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true') 4 | 5 | hotClient.subscribe(function (event) { 6 | if (event.action === 'reload') { 7 | window.location.reload() 8 | } 9 | }) 10 | -------------------------------------------------------------------------------- /build/dev-server.js: -------------------------------------------------------------------------------- 1 | require('./check-versions')() 2 | 3 | var config = require('../config') 4 | if (!process.env.NODE_ENV) { 5 | process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) 6 | } 7 | 8 | var opn = require('opn') 9 | var path = require('path') 10 | var express = require('express') 11 | var webpack = require('webpack') 12 | var proxyMiddleware = require('http-proxy-middleware') 13 | var webpackConfig = require('./webpack.dev.conf') 14 | 15 | // default port where dev server listens for incoming traffic 16 | var port = process.env.PORT || config.dev.port 17 | // automatically open browser, if not set will be false 18 | var autoOpenBrowser = !!config.dev.autoOpenBrowser 19 | // Define HTTP proxies to your custom API backend 20 | // https://github.com/chimurai/http-proxy-middleware 21 | var proxyTable = config.dev.proxyTable 22 | 23 | var app = express() 24 | var compiler = webpack(webpackConfig) 25 | 26 | var devMiddleware = require('webpack-dev-middleware')(compiler, { 27 | publicPath: webpackConfig.output.publicPath, 28 | quiet: true 29 | }) 30 | 31 | var hotMiddleware = require('webpack-hot-middleware')(compiler, { 32 | log: () => {} 33 | }) 34 | // force page reload when html-webpack-plugin template changes 35 | compiler.plugin('compilation', function (compilation) { 36 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 37 | hotMiddleware.publish({ action: 'reload' }) 38 | cb() 39 | }) 40 | }) 41 | 42 | // proxy api requests 43 | Object.keys(proxyTable).forEach(function (context) { 44 | var options = proxyTable[context] 45 | if (typeof options === 'string') { 46 | options = { target: options } 47 | } 48 | app.use(proxyMiddleware(options.filter || context, options)) 49 | }) 50 | 51 | // handle fallback for HTML5 history API 52 | app.use(require('connect-history-api-fallback')()) 53 | 54 | // serve webpack bundle output 55 | app.use(devMiddleware) 56 | 57 | // enable hot-reload and state-preserving 58 | // compilation error display 59 | app.use(hotMiddleware) 60 | 61 | // serve pure static assets 62 | var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) 63 | app.use(staticPath, express.static('./static')) 64 | 65 | var uri = 'http://localhost:' + port 66 | 67 | devMiddleware.waitUntilValid(function () { 68 | console.log('> Listening at ' + uri + '\n') 69 | }) 70 | 71 | module.exports = app.listen(port, function (err) { 72 | if (err) { 73 | console.log(err) 74 | return 75 | } 76 | 77 | // when env is testing, don't need open it 78 | if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { 79 | opn(uri) 80 | } 81 | }) 82 | -------------------------------------------------------------------------------- /build/utils.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var config = require('../config') 3 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 4 | 5 | exports.assetsPath = function (_path) { 6 | var assetsSubDirectory = process.env.NODE_ENV === 'production' 7 | ? config.build.assetsSubDirectory 8 | : config.dev.assetsSubDirectory 9 | return path.posix.join(assetsSubDirectory, _path) 10 | } 11 | 12 | exports.cssLoaders = function (options) { 13 | options = options || {} 14 | 15 | var cssLoader = { 16 | loader: 'css-loader', 17 | options: { 18 | minimize: process.env.NODE_ENV === 'production', 19 | sourceMap: options.sourceMap 20 | } 21 | } 22 | 23 | // generate loader string to be used with extract text plugin 24 | function generateLoaders (loader, loaderOptions) { 25 | var loaders = [cssLoader] 26 | if (loader) { 27 | loaders.push({ 28 | loader: loader + '-loader', 29 | options: Object.assign({}, loaderOptions, { 30 | sourceMap: options.sourceMap 31 | }) 32 | }) 33 | } 34 | 35 | // Extract CSS when that option is specified 36 | // (which is the case during production build) 37 | if (options.extract) { 38 | return ExtractTextPlugin.extract({ 39 | use: loaders, 40 | fallback: 'vue-style-loader' 41 | }) 42 | } else { 43 | return ['vue-style-loader'].concat(loaders) 44 | } 45 | } 46 | 47 | // http://vuejs.github.io/vue-loader/en/configurations/extract-css.html 48 | return { 49 | css: generateLoaders(), 50 | postcss: generateLoaders(), 51 | less: generateLoaders('less'), 52 | sass: generateLoaders('sass', { indentedSyntax: true }), 53 | scss: generateLoaders('sass'), 54 | stylus: generateLoaders('stylus'), 55 | styl: generateLoaders('stylus') 56 | } 57 | } 58 | 59 | // Generate loaders for standalone style files (outside of .vue) 60 | exports.styleLoaders = function (options) { 61 | var output = [] 62 | var loaders = exports.cssLoaders(options) 63 | for (var extension in loaders) { 64 | var loader = loaders[extension] 65 | output.push({ 66 | test: new RegExp('\\.' + extension + '$'), 67 | use: loader 68 | }) 69 | } 70 | return output 71 | } 72 | -------------------------------------------------------------------------------- /build/vue-loader.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var config = require('../config') 3 | var isProduction = process.env.NODE_ENV === 'production' 4 | 5 | module.exports = { 6 | loaders: utils.cssLoaders({ 7 | sourceMap: isProduction 8 | ? config.build.productionSourceMap 9 | : config.dev.cssSourceMap, 10 | extract: isProduction 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /build/webpack.base.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var config = require('../config') 4 | var vueLoaderConfig = require('./vue-loader.conf') 5 | 6 | function resolve (dir) { 7 | return path.join(__dirname, '..', dir) 8 | } 9 | 10 | module.exports = { 11 | entry: { 12 | app: './src/app.js' 13 | }, 14 | output: { 15 | path: config.build.assetsRoot, 16 | filename: '[name].js', 17 | publicPath: process.env.NODE_ENV === 'production' 18 | ? config.build.assetsPublicPath 19 | : config.dev.assetsPublicPath 20 | }, 21 | resolve: { 22 | extensions: ['.js', '.vue', '.json'], 23 | alias: { 24 | 'vue$': 'vue/dist/vue.esm.js', 25 | '@': resolve('src'), 26 | 'src': path.join(__dirname, '../src'), 27 | '_variable.less': path.join(__dirname, '../src/skin/_variable.less'), 28 | '_base.less': path.join(__dirname, '../src/skin/_base.less') 29 | } 30 | }, 31 | module: { 32 | rules: [ 33 | { 34 | test: /\.vue$/, 35 | loader: 'vue-loader', 36 | options: vueLoaderConfig 37 | }, 38 | { 39 | test: /\.js$/, 40 | loader: 'babel-loader', 41 | include: [resolve('src')] 42 | }, 43 | { 44 | test: /\.json$/, 45 | loader: 'json-loader' 46 | }, 47 | { 48 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, 49 | loader: 'url-loader', 50 | query: { 51 | limit: 10000, 52 | name: utils.assetsPath('img/[name].[hash:7].[ext]') 53 | } 54 | }, 55 | { 56 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, 57 | loader: 'url-loader', 58 | query: { 59 | limit: 10000, 60 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]') 61 | } 62 | } 63 | ] 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /build/webpack.dev.conf.js: -------------------------------------------------------------------------------- 1 | var utils = require('./utils') 2 | var webpack = require('webpack') 3 | var config = require('../config') 4 | var merge = require('webpack-merge') 5 | var baseWebpackConfig = require('./webpack.base.conf') 6 | var HtmlWebpackPlugin = require('html-webpack-plugin') 7 | var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin') 8 | 9 | // add hot-reload related code to entry chunks 10 | Object.keys(baseWebpackConfig.entry).forEach(function (name) { 11 | baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) 12 | }) 13 | 14 | module.exports = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) 17 | }, 18 | // cheap-module-eval-source-map is faster for development 19 | devtool: '#cheap-module-eval-source-map', 20 | plugins: [ 21 | new webpack.DefinePlugin({ 22 | 'process.env': config.dev.env 23 | }), 24 | // https://github.com/glenjamin/webpack-hot-middleware#installation--usage 25 | new webpack.HotModuleReplacementPlugin(), 26 | new webpack.NoEmitOnErrorsPlugin(), 27 | // https://github.com/ampedandwired/html-webpack-plugin 28 | new HtmlWebpackPlugin({ 29 | filename: 'index.html', 30 | template: 'index.html', 31 | inject: true 32 | }), 33 | new FriendlyErrorsPlugin() 34 | ] 35 | }) 36 | -------------------------------------------------------------------------------- /build/webpack.prod.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var webpack = require('webpack') 4 | var config = require('../config') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var CopyWebpackPlugin = require('copy-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 11 | 12 | var env = config.build.env 13 | 14 | var webpackConfig = merge(baseWebpackConfig, { 15 | module: { 16 | rules: utils.styleLoaders({ 17 | sourceMap: config.build.productionSourceMap, 18 | extract: true 19 | }) 20 | }, 21 | devtool: config.build.productionSourceMap ? '#source-map' : false, 22 | output: { 23 | path: config.build.assetsRoot, 24 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 25 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 26 | }, 27 | plugins: [ 28 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 29 | new webpack.DefinePlugin({ 30 | 'process.env': env 31 | }), 32 | new webpack.optimize.UglifyJsPlugin({ 33 | compress: { 34 | warnings: false 35 | }, 36 | sourceMap: true 37 | }), 38 | // extract css into its own file 39 | new ExtractTextPlugin({ 40 | filename: utils.assetsPath('css/[name].[contenthash].css') 41 | }), 42 | // Compress extracted CSS. We are using this plugin so that possible 43 | // duplicated CSS from different components can be deduped. 44 | new OptimizeCSSPlugin(), 45 | // generate dist index.html with correct asset hash for caching. 46 | // you can customize output by editing /index.html 47 | // see https://github.com/ampedandwired/html-webpack-plugin 48 | new HtmlWebpackPlugin({ 49 | filename: config.build.index, 50 | template: 'index.html', 51 | inject: true, 52 | minify: { 53 | removeComments: true, 54 | collapseWhitespace: true, 55 | removeAttributeQuotes: true 56 | // more options: 57 | // https://github.com/kangax/html-minifier#options-quick-reference 58 | }, 59 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 60 | chunksSortMode: 'dependency' 61 | }), 62 | // split vendor js into its own file 63 | new webpack.optimize.CommonsChunkPlugin({ 64 | name: 'vendor', 65 | minChunks: function (module, count) { 66 | // any required modules inside node_modules are extracted to vendor 67 | return ( 68 | module.resource && 69 | /\.js$/.test(module.resource) && 70 | module.resource.indexOf( 71 | path.join(__dirname, '../node_modules') 72 | ) === 0 73 | ) 74 | } 75 | }), 76 | // extract webpack runtime and module manifest to its own file in order to 77 | // prevent vendor hash from being updated whenever app bundle is updated 78 | new webpack.optimize.CommonsChunkPlugin({ 79 | name: 'manifest', 80 | chunks: ['vendor'] 81 | }), 82 | // copy custom static assets 83 | new CopyWebpackPlugin([ 84 | { 85 | from: path.resolve(__dirname, '../static'), 86 | to: config.build.assetsSubDirectory, 87 | ignore: ['.*'] 88 | } 89 | ]) 90 | ] 91 | }) 92 | 93 | if (config.build.productionGzip) { 94 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 95 | 96 | webpackConfig.plugins.push( 97 | new CompressionWebpackPlugin({ 98 | asset: '[path].gz[query]', 99 | algorithm: 'gzip', 100 | test: new RegExp( 101 | '\\.(' + 102 | config.build.productionGzipExtensions.join('|') + 103 | ')$' 104 | ), 105 | threshold: 10240, 106 | minRatio: 0.8 107 | }) 108 | ) 109 | } 110 | 111 | if (config.build.bundleAnalyzerReport) { 112 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 113 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 114 | } 115 | 116 | module.exports = webpackConfig 117 | -------------------------------------------------------------------------------- /build/webpack.publish.conf.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var utils = require('./utils') 3 | var webpack = require('webpack') 4 | var config = require('../config') 5 | var merge = require('webpack-merge') 6 | var baseWebpackConfig = require('./webpack.base.conf') 7 | var CopyWebpackPlugin = require('copy-webpack-plugin') 8 | var HtmlWebpackPlugin = require('html-webpack-plugin') 9 | var ExtractTextPlugin = require('extract-text-webpack-plugin') 10 | var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin') 11 | var PrerenderSpaPlugin = require('prerender-spa-plugin') 12 | 13 | var env = config.build.env 14 | 15 | module.exports = function(env) { 16 | let dir = path.join(__dirname, '../public/' + env.id) 17 | 18 | var webpackConfig = merge(baseWebpackConfig, { 19 | module: { 20 | rules: utils.styleLoaders({ 21 | sourceMap: config.build.productionSourceMap, 22 | extract: true 23 | }) 24 | }, 25 | devtool: config.build.productionSourceMap ? '#source-map' : false, 26 | output: { 27 | path: config.build.assetsRoot, 28 | filename: utils.assetsPath('js/[name].[chunkhash].js'), 29 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') 30 | }, 31 | plugins: [ 32 | // http://vuejs.github.io/vue-loader/en/workflow/production.html 33 | new webpack.DefinePlugin({ 34 | 'process.env': env 35 | }), 36 | new webpack.optimize.UglifyJsPlugin({ 37 | compress: { 38 | warnings: false 39 | }, 40 | sourceMap: true 41 | }), 42 | // extract css into its own file 43 | new ExtractTextPlugin({ 44 | filename: utils.assetsPath('css/[name].[contenthash].css') 45 | }), 46 | // Compress extracted CSS. We are using this plugin so that possible 47 | // duplicated CSS from different components can be deduped. 48 | new OptimizeCSSPlugin({ 49 | canPrint: false 50 | }), 51 | // generate dist index.html with correct asset hash for caching. 52 | // you can customize output by editing /index.html 53 | // see https://github.com/ampedandwired/html-webpack-plugin 54 | new HtmlWebpackPlugin({ 55 | filename: 'index.html', 56 | template: dir + `/index.html`, 57 | inject: true, 58 | minify: { 59 | removeComments: true, 60 | collapseWhitespace: true, 61 | removeAttributeQuotes: true 62 | // more options: 63 | // https://github.com/kangax/html-minifier#options-quick-reference 64 | }, 65 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin 66 | chunksSortMode: 'dependency' 67 | }), 68 | // split vendor js into its own file 69 | new webpack.optimize.CommonsChunkPlugin({ 70 | name: 'vendor', 71 | minChunks: function (module, count) { 72 | // any required modules inside node_modules are extracted to vendor 73 | return ( 74 | module.resource && 75 | /\.js$/.test(module.resource) && 76 | module.resource.indexOf( 77 | path.join(__dirname, '../node_modules') 78 | ) === 0 79 | ) 80 | } 81 | }), 82 | // extract webpack runtime and module manifest to its own file in order to 83 | // prevent vendor hash from being updated whenever app bundle is updated 84 | new webpack.optimize.CommonsChunkPlugin({ 85 | name: 'manifest', 86 | chunks: ['vendor'] 87 | }), 88 | // copy custom static assets 89 | new CopyWebpackPlugin([ 90 | { 91 | from: path.resolve(__dirname, '../static'), 92 | to: config.build.assetsSubDirectory, 93 | ignore: ['.*'] 94 | } 95 | ]), 96 | // page pre render 97 | new PrerenderSpaPlugin( 98 | dir, 99 | [ '/' ], 100 | { 101 | captureAfterElementExists: '#preview' 102 | } 103 | ) 104 | ] 105 | }) 106 | 107 | if (config.build.productionGzip) { 108 | var CompressionWebpackPlugin = require('compression-webpack-plugin') 109 | 110 | webpackConfig.plugins.push( 111 | new CompressionWebpackPlugin({ 112 | asset: '[path].gz[query]', 113 | algorithm: 'gzip', 114 | test: new RegExp( 115 | '\\.(' + 116 | config.build.productionGzipExtensions.join('|') + 117 | ')$' 118 | ), 119 | threshold: 10240, 120 | minRatio: 0.8 121 | }) 122 | ) 123 | } 124 | 125 | webpackConfig.entry = { 126 | preview: './src/preview.js' 127 | } 128 | 129 | webpackConfig.output.publicPath = './' 130 | webpackConfig.output.path = dir 131 | 132 | if (config.build.bundleAnalyzerReport) { 133 | var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin 134 | webpackConfig.plugins.push(new BundleAnalyzerPlugin()) 135 | } 136 | 137 | return webpackConfig 138 | } 139 | -------------------------------------------------------------------------------- /config/db.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | 3 | let { 4 | DATABASE_DIALECT = 'mysql', 5 | DATABASE_STORAGE = './db.sqlite', 6 | DATABASE_HOST = '127.0.0.1', 7 | DATABASE_PORT = 3306, 8 | DATABASE_NAME = 'piper', 9 | DATABASE_USER, 10 | DATABASE_PASSWORD, 11 | DATABASE_URL 12 | } = process.env; 13 | 14 | let base = { 15 | "username": DATABASE_USER, 16 | "password": DATABASE_PASSWORD, 17 | "database": DATABASE_NAME, 18 | "host": DATABASE_HOST, 19 | "port": DATABASE_PORT, 20 | "dialect": DATABASE_DIALECT, 21 | "storage": DATABASE_STORAGE, 22 | "url": DATABASE_URL 23 | }; 24 | 25 | module.exports = { 26 | "development": base, 27 | "test": base, 28 | "production": base 29 | } 30 | -------------------------------------------------------------------------------- /config/dev.env.js: -------------------------------------------------------------------------------- 1 | var merge = require('webpack-merge') 2 | var prodEnv = require('./prod.env') 3 | 4 | module.exports = merge(prodEnv, { 5 | NODE_ENV: '"development"' 6 | }) 7 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | // see http://vuejs-templates.github.io/webpack for documentation. 2 | var path = require('path') 3 | 4 | module.exports = { 5 | build: { 6 | env: require('./prod.env'), 7 | index: path.resolve(__dirname, '../dist/index.html'), 8 | assetsRoot: path.resolve(__dirname, '../dist'), 9 | assetsSubDirectory: 'static', 10 | assetsPublicPath: '/', 11 | productionSourceMap: true, 12 | // Gzip off by default as many popular static hosts such as 13 | // Surge or Netlify already gzip all static assets for you. 14 | // Before setting to `true`, make sure to: 15 | // npm install --save-dev compression-webpack-plugin 16 | productionGzip: false, 17 | productionGzipExtensions: ['js', 'css'], 18 | // Run the build command with an extra argument to 19 | // View the bundle analyzer report after build finishes: 20 | // `npm run build --report` 21 | // Set to `true` or `false` to always turn it on or off 22 | bundleAnalyzerReport: process.env.npm_config_report 23 | }, 24 | dev: { 25 | env: require('./dev.env'), 26 | port: 8080, 27 | autoOpenBrowser: true, 28 | assetsSubDirectory: 'static', 29 | assetsPublicPath: '/', 30 | proxyTable: {}, 31 | // CSS Sourcemaps off by default because relative paths are "buggy" 32 | // with this option, according to the CSS-Loader README 33 | // (https://github.com/webpack/css-loader#sourcemaps) 34 | // In our experience, they generally work as expected, 35 | // just be aware of this issue when enabling this option. 36 | cssSourceMap: false 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /config/prod.env.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | NODE_ENV: '"production"' 3 | } 4 | -------------------------------------------------------------------------------- /docs/功能.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fireyy/piper/55f254709184991d26d37327e6408a9cedfc7654/docs/功能.xmind -------------------------------------------------------------------------------- /docs/结构.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fireyy/piper/55f254709184991d26d37327e6408a9cedfc7654/docs/结构.xmind -------------------------------------------------------------------------------- /env.sample: -------------------------------------------------------------------------------- 1 | DATABASE_DIALECT=mysql 2 | DATABASE_HOST=127.0.0.1 3 | DATABASE_PORT=3306 4 | DATABASE_NAME=piper 5 | DATABASE_USER=root 6 | DATABASE_PASSWORD= 7 | QINIU_ACCESS_KEY=YOUR QINIU AK 8 | QINIU_SECRET_KEY=YOUR QINIU SK 9 | QINIU_BUCKET=YOUR QINIU BUCKET 10 | QINIU_BASEURL=YOUR QINIU URL 11 | OPADS_URL=YOUR OPADS URL 12 | OPADS_PROJECT=YOUR OPADS PROJECT 13 | OPADS_AUTHKEY=YOUR OPADS AUTHKEY 14 | GITHUB_CLIENT_ID= 15 | GITHUB_CLIENT_SECRET= 16 | GITHUB_CLIENT_CALLBACK_URL= 17 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Piper 9 | 10 | 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | require('./build/check-versions')() 2 | 3 | const port = process.env.PORT || 4000; 4 | const env = process.env.NODE_ENV || 'development'; 5 | const src = env === 'production' ? './dist/index' : './server/index'; 6 | const config = require('./config') 7 | 8 | const app = require(src); 9 | 10 | // check database 11 | const models = require('./server/models') 12 | models.sequelize.sync().then(function(){ 13 | app.listen(port, function(err) { 14 | if (err) { 15 | console.log(err) 16 | return 17 | } 18 | 19 | var uri = 'http://localhost:' + port 20 | 21 | console.log('> Listening at ' + uri + '\n') 22 | }); 23 | }).catch(function(err){ 24 | console.error(new Error(err)) 25 | }); 26 | -------------------------------------------------------------------------------- /migrations/201706161508_add_avatar_field_to_users.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | up: function (queryInterface, Sequelize) { 3 | 4 | queryInterface.describeTable('users').then(function(attributes){ 5 | 6 | if (attributes.hasOwnProperty('avatar')) { 7 | return 1; 8 | } 9 | 10 | return queryInterface.addColumn( 11 | 'users', 12 | 'avatar', 13 | { 14 | type : Sequelize.STRING(64), 15 | allowNull : true, 16 | defaultValue : '', 17 | } 18 | ); 19 | }); 20 | }, 21 | 22 | down: function (queryInterface, Sequelize) { 23 | return queryInterface.removeColumn('users', 'avatar'); 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "piper", 3 | "version": "1.0.5", 4 | "description": "A drag-and-drop mobile website builder base on Vue.", 5 | "engines": { 6 | "node": ">=7.6.0", 7 | "npm": ">=3.0.0" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/fireyy/piper.git" 12 | }, 13 | "keywords": [ 14 | "vue", 15 | "drag-and-drop", 16 | "drag", 17 | "builder", 18 | "editor", 19 | "page-builder" 20 | ], 21 | "author": "fireyy ", 22 | "browserslist": [ 23 | "> 1%", 24 | "last 2 versions", 25 | "not ie <= 8" 26 | ], 27 | "scripts": { 28 | "build": "npm run build:client && npm run build:server", 29 | "build:client": "webpack --config build/webpack.prod.conf.js", 30 | "build:server": "babel server --out-dir dist", 31 | "server": "node index.js", 32 | "start": "NODE_ENV=production node index.js", 33 | "dev": "nodemon --watch server --watch build --exec npm run server", 34 | "db:update": "node node_modules/.bin/sequelize db:migrate --config=config/db.js", 35 | "postinstall": "npm run build" 36 | }, 37 | "dependencies": { 38 | "async-busboy": "^0.3.4", 39 | "axios": "^0.16.2", 40 | "babel-polyfill": "^6.23.0", 41 | "co": "^4.6.0", 42 | "co-views": "^2.1.0", 43 | "dotenv": "^4.0.0", 44 | "ejs": "^2.5.6", 45 | "element-ui": "^1.2.4", 46 | "interactjs": "^1.2.8", 47 | "koa": "^2.1.0", 48 | "koa-bodyparser": "^4.1.0", 49 | "koa-passport": "^3.0.0", 50 | "koa-router": "^7.0.0", 51 | "koa-session": "^5.1.0", 52 | "koa-static": "^3.0.0", 53 | "lodash": "^4.17.4", 54 | "mysql2": "^1.3.3", 55 | "passport-github": "^1.1.0", 56 | "pg": "^6.4.2", 57 | "pg-hstore": "^2.3.2", 58 | "qiniu": "^6.1.13", 59 | "qr.js": "0.0.0", 60 | "request": "^2.81.0", 61 | "request-promise": "^4.1.1", 62 | "sequelize": "^4.0.0", 63 | "sequelize-cli": "^2.7.0", 64 | "sqlite3": "^3.1.9", 65 | "vue": "^2.2.2", 66 | "vue-awesome": "^2.3.1", 67 | "vue-router": "^2.3.0", 68 | "vuex": "^2.2.1", 69 | "vuex-router-sync": "^4.1.2", 70 | "webshot": "^0.18.0" 71 | }, 72 | "devDependencies": { 73 | "autoprefixer": "^6.7.7", 74 | "babel-cli": "^6.24.1", 75 | "babel-core": "^6.24.0", 76 | "babel-loader": "^6.4.0", 77 | "babel-plugin-lodash": "^3.2.11", 78 | "babel-plugin-transform-decorators-legacy": "^1.3.4", 79 | "babel-plugin-transform-runtime": "^6.22.0", 80 | "babel-preset-env": "^1.2.1", 81 | "babel-preset-stage-2": "^6.22.0", 82 | "babel-register": "^6.22.0", 83 | "chalk": "^1.1.3", 84 | "connect-history-api-fallback": "^1.1.0", 85 | "copy-webpack-plugin": "^4.0.1", 86 | "css-loader": "^0.27.2", 87 | "eventsource-polyfill": "^0.9.6", 88 | "extract-text-webpack-plugin": "^2.1.0", 89 | "file-loader": "^0.10.1", 90 | "friendly-errors-webpack-plugin": "^1.1.3", 91 | "function-bind": "^1.1.0", 92 | "html-webpack-plugin": "^2.28.0", 93 | "http-proxy-middleware": "^0.17.4", 94 | "json-loader": "^0.5.4", 95 | "koa-convert": "^1.2.0", 96 | "koa-webpack-dev-middleware": "^1.4.4", 97 | "koa-webpack-hot-middleware": "^1.0.3", 98 | "less": "^2.7.2", 99 | "less-loader": "^3.0.0", 100 | "lodash-webpack-plugin": "^0.11.2", 101 | "memory-fs": "^0.4.1", 102 | "mkdirp": "^0.5.1", 103 | "nodemon": "^1.11.0", 104 | "opn": "^4.0.2", 105 | "optimize-css-assets-webpack-plugin": "^1.3.0", 106 | "ora": "^1.1.0", 107 | "postcss-loader": "^1.3.3", 108 | "postcss-pxtorem": "^4.0.0", 109 | "prerender-spa-plugin": "^2.0.1", 110 | "progress-bar-webpack-plugin": "^1.9.3", 111 | "raw-loader": "^0.5.1", 112 | "rimraf": "^2.6.0", 113 | "semver": "^5.3.0", 114 | "style-loader": "^0.13.2", 115 | "url-loader": "^0.5.8", 116 | "vue-hot-reload-api": "^2.0.11", 117 | "vue-loader": "^11.1.4", 118 | "vue-style-loader": "^2.0.3", 119 | "vue-template-compiler": "^2.2.2", 120 | "webpack": "^2.2.1", 121 | "webpack-bundle-analyzer": "^2.2.1", 122 | "webpack-dev-middleware": "^1.10.1", 123 | "webpack-hot-middleware": "^2.17.1", 124 | "webpack-merge": "^2.6.1" 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /public/3/index.html: -------------------------------------------------------------------------------- 1 | 网页标题0000
2 | -------------------------------------------------------------------------------- /screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fireyy/piper/55f254709184991d26d37327e6408a9cedfc7654/screen.png -------------------------------------------------------------------------------- /server/constants.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | VALUE_MAX_LENGTH: 10240, 3 | VALUE_TOO_LONG: { 4 | status: 400, 5 | message: 'Value 不能大于 10240 个字符', 6 | name: 'VALUE_TOO_LONG' 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /server/controllers/changelogs.js: -------------------------------------------------------------------------------- 1 | const models = require('../models'); 2 | 3 | module.exports = class { 4 | constructor() { 5 | this.url = '/changelogs'; 6 | } 7 | 8 | async get(ctx) { 9 | let { page, size, title, action } = ctx.query; 10 | page = parseInt(page, 10) 11 | size = parseInt(size, 10) 12 | let start = (page - 1) * size; 13 | let limit = size; 14 | let where = {}; 15 | if (title) { 16 | where['$page.title$'] = { 17 | $like: `%${title}%` 18 | } 19 | } 20 | if (action && action != 0) { 21 | where['action'] = action 22 | } 23 | console.log("where", where) 24 | 25 | let result = await models.changelog.findAndCountAll({ 26 | attributes: ['action', 'create_at'], 27 | include: [ 28 | { 29 | model: models.pages, 30 | attributes: ['title'] 31 | }, 32 | { 33 | model: models.users, 34 | attributes: ['name'] 35 | } 36 | ], 37 | offset: start, 38 | limit: limit, 39 | where: where, 40 | order: [['create_at', 'DESC']] 41 | }); 42 | 43 | ctx.body = { 44 | total: result.count, 45 | page: page, 46 | size: size, 47 | data: result.rows 48 | } 49 | } 50 | 51 | }; 52 | -------------------------------------------------------------------------------- /server/controllers/count.js: -------------------------------------------------------------------------------- 1 | const models = require('../models') 2 | 3 | module.exports = class { 4 | constructor() { 5 | this.url = '/count'; 6 | } 7 | 8 | async get(ctx) { 9 | let [result] = await models.pages.findAll({ 10 | attributes: [ 11 | [models.sequelize.fn('COUNT', models.sequelize.literal('CASE WHEN is_publish = 0 THEN 1 ELSE NULL END')), 'working'], 12 | [models.sequelize.fn('COUNT', models.sequelize.literal('CASE WHEN is_publish = 1 THEN 1 ELSE NULL END')), 'published'] 13 | ], 14 | where: { 15 | is_delete: 0 16 | } 17 | }) 18 | 19 | ctx.body = result; 20 | } 21 | 22 | }; 23 | -------------------------------------------------------------------------------- /server/controllers/files.js: -------------------------------------------------------------------------------- 1 | const asyncBusboy = require('async-busboy'); 2 | const upload = require('../lib/publish'); 3 | 4 | module.exports = class { 5 | constructor() { 6 | this.url = '/files'; 7 | } 8 | 9 | async post(ctx) { 10 | const {files, fields} = await asyncBusboy(ctx.req); 11 | 12 | let uploadRes = await upload(files); 13 | 14 | ctx.body = uploadRes 15 | } 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /server/controllers/page.js: -------------------------------------------------------------------------------- 1 | const __ = require("../constants"); 2 | const models = require("../models"); 3 | 4 | module.exports = class { 5 | constructor() { 6 | this.url = '/page/:id'; 7 | } 8 | 9 | async delete(ctx) { 10 | let { id } = ctx.params; 11 | 12 | await models.pages.update( 13 | { 14 | is_delete: 1 15 | }, 16 | { 17 | where: { 18 | id: id 19 | } 20 | } 21 | ); 22 | 23 | await models.changelog.create({ 24 | action: 3, 25 | page_id: id, 26 | items: null, 27 | create_by: ctx.state.user.id 28 | }); 29 | 30 | ctx.body = { 31 | message: "Delete success" 32 | }; 33 | } 34 | 35 | async get(ctx) { 36 | let { id } = ctx.params; 37 | 38 | let result = await models.pages.findAll( 39 | { 40 | where: { 41 | is_delete: 0, 42 | id: id 43 | } 44 | } 45 | ); 46 | 47 | let page = result[0]; 48 | if (!page) 49 | throw { 50 | status: 404, 51 | name: "PAGES_NOT_FOUND", 52 | message: "page is not found" 53 | }; 54 | 55 | try { 56 | if (page.items) page.items = JSON.parse(page.items); 57 | if (page.config) page.config = JSON.parse(page.config); 58 | } catch (error) { 59 | throw { 60 | status: 500, 61 | name: "JSON_PARSE_ERROR", 62 | message: "json parse error" 63 | }; 64 | } 65 | 66 | ctx.body = page; 67 | } 68 | 69 | async put(ctx) { 70 | let { id } = ctx.params; 71 | let { body } = ctx.request; 72 | let change = Object.create(null); 73 | let count = ["title", "config", "items"].reduce((count, name) => { 74 | if (!(name in body)) return count; 75 | change[name] = body[name]; 76 | return count + 1; 77 | }, 0); 78 | 79 | if (count === 0) 80 | throw { 81 | status: 400, 82 | name: "ERR", 83 | message: "require `title` or/and `items` in request body" 84 | }; 85 | 86 | change.title = change.title.trim(); 87 | 88 | if (!change.title) 89 | throw { status: 400, name: "ERROR_PARAMS", message: "Title 不能为空" }; 90 | 91 | if ("items" in change) { 92 | change.items = JSON.stringify(change.items); 93 | if (change.items.length > __.VALUE_MAX_LENGTH) throw __.VALUE_TOO_LONG; 94 | } 95 | if ("config" in change) { 96 | change.config = JSON.stringify(change.config); 97 | } 98 | 99 | let [page] = await models.pages.findAll({ 100 | attributes: ['is_delete', 'items'], 101 | where: { 102 | id: id 103 | } 104 | }) 105 | 106 | if (!page || page.is_delete) 107 | throw { 108 | status: 404, 109 | name: "PAGE_NOT_FOUND", 110 | message: "page is not found" 111 | }; 112 | 113 | await models.pages.update( 114 | change, 115 | { 116 | where: { 117 | id: id 118 | } 119 | } 120 | ); 121 | 122 | let changed = ["title", "config", "items"].reduce((changed, name) => { 123 | return page[name] !== change[name] ? changed + 1 : changed; 124 | }, 0); 125 | if (changed > 0) { 126 | await models.changelog.create({ 127 | action: 2, 128 | page_id: id, 129 | items: change.items, 130 | create_by: ctx.state.user.id 131 | }); 132 | } 133 | 134 | ctx.body = { 135 | message: "Save success" 136 | }; 137 | } 138 | }; 139 | -------------------------------------------------------------------------------- /server/controllers/pages.js: -------------------------------------------------------------------------------- 1 | const models = require('../models'); 2 | const __ = require('../constants'); 3 | 4 | module.exports = class { 5 | constructor() { 6 | this.url = '/pages'; 7 | } 8 | 9 | async get(ctx) { 10 | let { page, size, title, isPublish } = ctx.query; 11 | page = parseInt(page, 10) 12 | size = parseInt(size, 10) 13 | let start = (page - 1) * size; 14 | let limit = size; 15 | let where = { 16 | is_delete: 0 17 | }; 18 | if (title) { 19 | where['title'] = { 20 | $like: `%${title}%` 21 | } 22 | } 23 | if (isPublish != -1) { 24 | where['is_publish'] = isPublish 25 | } 26 | let result = await models.pages.findAndCountAll({ 27 | include: [ 28 | { 29 | model: models.users, 30 | attributes: ['name'] 31 | } 32 | ], 33 | offset: start, 34 | limit: limit, 35 | where: where, 36 | order: [['create_at', 'DESC']] 37 | }); 38 | 39 | ctx.body = { 40 | total: result.count, 41 | page: page, 42 | size: size, 43 | data: result.rows 44 | }; 45 | } 46 | 47 | async put(ctx) { 48 | let { title = '', config = '', items = '' } = ctx.request.body; 49 | title = title.trim(); 50 | if (!title) throw { status: 400, name: 'ERROR_PARAMS', message: 'Title 不能为空' }; 51 | items = JSON.stringify(items); 52 | if (items.length > __.VALUE_MAX_LENGTH) throw __.VALUE_TOO_LONG; 53 | config = JSON.stringify(config); 54 | 55 | let [page, created] = await models.pages.findOrCreate({ 56 | where: { 57 | is_delete: 0, 58 | title: title 59 | }, 60 | defaults: { 61 | title: title, 62 | config: config, 63 | items: items, 64 | create_by: ctx.state.user.id 65 | } 66 | }); 67 | 68 | if (page && !created) { 69 | throw { status: 400, name: 'DUP', message: '记录已存在' }; 70 | } 71 | 72 | await models.changelog.create({ 73 | action: 1, 74 | page_id: page.id, 75 | items: items, 76 | create_by: ctx.state.user.id 77 | }) 78 | 79 | ctx.body = { 80 | message: 'Save success', 81 | item: page 82 | }; 83 | } 84 | 85 | }; 86 | -------------------------------------------------------------------------------- /server/controllers/publish.js: -------------------------------------------------------------------------------- 1 | const pageApi = require('./page'); 2 | const models = require("../models"); 3 | 4 | const path = require('path'); 5 | const views = require('co-views'); 6 | const child_process = require('child_process'); 7 | const fs = require('fs'); 8 | const mkdirp = require('mkdirp'); 9 | const render = views(path.join(__dirname, '../views'), { ext: 'ejs' }); 10 | const upload = require('../lib/publish'); 11 | 12 | const webshot = require('webshot'); 13 | 14 | const protocol = 'http://' 15 | 16 | module.exports = class { 17 | constructor() { 18 | this.url = '/publish/:id'; 19 | } 20 | 21 | async get(ctx) { 22 | let { id } = ctx.params; 23 | 24 | let result = await models.pages.findAll({ 25 | where: { 26 | is_delete: 0, 27 | id: id 28 | } 29 | }); 30 | 31 | let page = result[0]; 32 | if (!page) throw { status: 404, name: 'PAGES_NOT_FOUND', message: 'page is not found' }; 33 | try { page.items = JSON.parse(page.items); } catch(error) { 34 | throw { status: 500, name: 'JSON_PARSE_ERROR', message: 'json parse error' } 35 | }; 36 | 37 | let html = await render('activity', { page: page }); 38 | 39 | ctx.body = html 40 | } 41 | 42 | async put(ctx) { 43 | // save data first 44 | await pageApi.put(ctx) 45 | 46 | let { id } = ctx.params; 47 | 48 | let [page] = await models.pages.findAll({ 49 | where: { 50 | is_delete: 0, 51 | id: id 52 | } 53 | }); 54 | 55 | if (!page) throw { status: 404, name: 'PAGES_NOT_FOUND', message: 'page is not found' }; 56 | 57 | await models.pages.update({ 58 | is_publish: 1, 59 | publish_at: Date.now() 60 | }, { 61 | where: { 62 | id: id 63 | } 64 | }) 65 | 66 | await models.changelog.create({ 67 | action: 4, 68 | page_id: id, 69 | items: null, 70 | create_by: ctx.state.user.id 71 | }); 72 | 73 | const dir = `public/${id}`; 74 | 75 | if (!fs.existsSync(dir)) { 76 | 77 | mkdirp(dir, function (err) { 78 | if (err) { 79 | console.error(err) 80 | } 81 | }); 82 | } 83 | 84 | try { 85 | page.config = JSON.parse(page.config); 86 | page.items = JSON.parse(page.items); 87 | } catch(error) { 88 | throw { status: 500, name: 'JSON_PARSE_ERROR', message: 'json parse error' } 89 | }; 90 | 91 | let html = await render('activity', { page: page }); 92 | 93 | await fs.writeFileSync(dir + `/index.html`, html, 'utf-8', {'flags': 'w+'}); 94 | 95 | const command = `NODE_ENV=production webpack --config ./build/webpack.publish.conf.js --env.id=${id} --hide-modules --json --verbose`; 96 | 97 | const stdout = child_process.execSync(command).toString(); 98 | 99 | let packRes = JSON.parse(stdout); 100 | 101 | if (packRes.errors.length == 0) { 102 | let files = packRes.assets.map(item => { 103 | return fs.createReadStream(dir + `/${item.name}`) 104 | }) 105 | let uploadRes = await upload(files); 106 | 107 | let shotUrl = uploadRes.filter(item => { 108 | return item.url.indexOf('index.html') !== -1 109 | }) 110 | shotUrl[0].url = protocol + shotUrl[0].url 111 | 112 | var options = { 113 | screenSize: { 114 | width: 375 115 | , height: 375 116 | } 117 | , shotSize: { 118 | width: 375 119 | , height: 'all' 120 | } 121 | , userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)' 122 | + ' AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g' 123 | }; 124 | 125 | webshot(shotUrl[0].url, `${dir}/cover.png`, options, function(err) { 126 | if(err) { 127 | throw { status: 404, name: 'WEBSHOT_ERR', message: 'webshot failed' }; 128 | } 129 | 130 | upload([fs.createReadStream(`${dir}/cover.png`)]).then((coverRes) => { 131 | models.pages.update({ 132 | cover: protocol + coverRes[0].url 133 | }, { 134 | where: { 135 | id: id 136 | } 137 | }) 138 | }) 139 | }); 140 | 141 | ctx.body = shotUrl 142 | } else { 143 | 144 | ctx.body = packRes; 145 | } 146 | 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /server/controllers/users.js: -------------------------------------------------------------------------------- 1 | const models = require('../models') 2 | 3 | module.exports = class { 4 | constructor() { 5 | this.url = '/users'; 6 | } 7 | 8 | async get(ctx) { 9 | let users = await models.users.findAll(); 10 | ctx.body = users; 11 | } 12 | 13 | }; 14 | -------------------------------------------------------------------------------- /server/index.js: -------------------------------------------------------------------------------- 1 | const koa = new (require('koa'))(); 2 | 3 | const env = process.env.NODE_ENV || 'development'; 4 | 5 | if (env === 'development') { 6 | // for dev 7 | const webpackConfig = require('../build/webpack.dev.conf'); 8 | const convert = require('koa-convert') 9 | const webpack = require('webpack') 10 | var compiler = webpack(webpackConfig) 11 | const webpackDevMiddleware = require("koa-webpack-dev-middleware") 12 | const webpackHotMiddleware = require("koa-webpack-hot-middleware") 13 | 14 | var devMiddleware = webpackDevMiddleware(compiler, { 15 | publicPath: webpackConfig.output.publicPath, 16 | quiet: true 17 | }) 18 | 19 | var hotMiddleware = webpackHotMiddleware(compiler, { 20 | log: () => {} 21 | }) 22 | // force page reload when html-webpack-plugin template changes 23 | compiler.plugin('compilation', function (compilation) { 24 | compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { 25 | hotMiddleware.publish({ action: 'reload' }) 26 | cb() 27 | }) 28 | }) 29 | 30 | koa.use(convert(devMiddleware)) 31 | koa.use(convert(hotMiddleware)) 32 | 33 | // for dev log 34 | koa.use(async (ctx, next) => { 35 | const start = new Date(); 36 | await next(); 37 | const ms = new Date() - start; 38 | console.log(`${ctx.method} ${ctx.url} - ${ms}ms`); 39 | }); 40 | } 41 | 42 | koa.keys = ['i-love-piper'] 43 | koa.use(require('koa-session')({}, koa)) 44 | 45 | koa.use(require('koa-bodyparser')()); 46 | koa.use(require('./lib/errorlog')); 47 | 48 | if (process.env.NEED_AUTH) { 49 | // authentication 50 | require('./lib/passport') 51 | const passport = require('koa-passport') 52 | koa.use(passport.initialize()) 53 | koa.use(passport.session()) 54 | 55 | const router = require('koa-router')() 56 | 57 | router.get('/auth/github', 58 | passport.authenticate('github') 59 | ) 60 | 61 | router.get('/auth/github/callback', 62 | passport.authenticate('github', { 63 | successRedirect: '/', 64 | failureRedirect: '/' 65 | }) 66 | ) 67 | 68 | koa.use(router.routes()) 69 | } else { 70 | koa.use(async function(ctx, next) { 71 | ctx.state.user = { 72 | id: 1, 73 | name: "fireyy" 74 | } 75 | await next() 76 | }) 77 | } 78 | 79 | koa.use(require('./lib/api')); 80 | koa.use(require('koa-static')('dist')); 81 | 82 | if (process.env.NEED_AUTH) { 83 | // Require authentication for now 84 | koa.use(function(ctx, next) { 85 | if (ctx.isAuthenticated()) { 86 | return next() 87 | } else { 88 | if (ctx.request.url.indexOf('/api/') !== -1) { 89 | throw { 90 | status: 401, 91 | name: 'NOT_LOGIN', 92 | message: 'not login' 93 | } 94 | } else { 95 | ctx.redirect('/') 96 | } 97 | } 98 | }) 99 | } 100 | 101 | module.exports = koa; 102 | -------------------------------------------------------------------------------- /server/lib/api.js: -------------------------------------------------------------------------------- 1 | const KoaRouter = require('koa-router'); 2 | const apiRouter = new KoaRouter({ prefix: '/api' }); 3 | const fs = require("fs"); 4 | const path = require('path'); 5 | 6 | const controllerPath = path.join(__dirname, '../controllers'); 7 | 8 | fs 9 | .readdirSync(controllerPath) 10 | .filter(function(file) { 11 | return (file.indexOf(".") !== 0) && (file !== "index.js"); 12 | }) 13 | .forEach(function(file) { 14 | let controllerClass = require(path.join(controllerPath, file)); 15 | let controller = new controllerClass(); 16 | for (let method of [ 'options', 'get', 'post', 'delete', 'put' ]) { 17 | if (method in controller) { 18 | apiRouter[method](controller.url, async (ctx, next) => { 19 | return controller[method](ctx).then(next); 20 | }); 21 | } 22 | } 23 | }); 24 | 25 | apiRouter.get('/logout', (ctx) => { 26 | ctx.logout() 27 | ctx.body = { 28 | message: 'success' 29 | } 30 | }) 31 | 32 | module.exports = apiRouter.routes(); 33 | -------------------------------------------------------------------------------- /server/lib/errorlog.js: -------------------------------------------------------------------------------- 1 | module.exports = async (ctx, next) => { 2 | try { 3 | return await next(); 4 | } catch (error) { 5 | let { status , name = 'UNKNOWN_ERROR', message = '' } = error; 6 | if (!status) console.error(error.stack || error); 7 | ctx.status = status || 500; 8 | ctx.body = { name, message }; 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /server/lib/passport.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config() 2 | const passport = require('koa-passport') 3 | const models = require('../models') 4 | 5 | passport.serializeUser(function(user, done) { 6 | done(null, user.id) 7 | }) 8 | 9 | passport.deserializeUser(async function(id, done) { 10 | try { 11 | const user = await models.users.findById(id) 12 | done(null, user) 13 | } catch(err) { 14 | done(err) 15 | } 16 | }) 17 | 18 | const GitHubStrategy = require('passport-github').Strategy; 19 | passport.use(new GitHubStrategy({ 20 | clientID: process.env.GITHUB_CLIENT_ID, 21 | clientSecret: process.env.GITHUB_CLIENT_SECRET, 22 | callbackURL: process.env.GITHUB_CLIENT_CALLBACK_URL 23 | }, 24 | function(accessToken, refreshToken, profile, cb) { 25 | let { 26 | name, 27 | email, 28 | id, 29 | avatar_url 30 | } = profile._json; 31 | models.users.findOrCreate({where: {github_id: id}, defaults: { 32 | name: name, 33 | email: email, 34 | avatar: avatar_url 35 | }}).spread((user, created) => cb(null, user)).catch(err => { 36 | console.log(err) 37 | }) 38 | } 39 | )); 40 | -------------------------------------------------------------------------------- /server/lib/publish/index.js: -------------------------------------------------------------------------------- 1 | const qiniu = require('./qiniu'); 2 | const opads = require('./opads'); 3 | 4 | module.exports = qiniu; 5 | -------------------------------------------------------------------------------- /server/lib/publish/opads.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const request = require('request-promise'); 3 | 4 | let { 5 | OPADS_URL, 6 | OPADS_PROJECT, 7 | OPADS_AUTHKEY 8 | } = process.env; 9 | 10 | const getUploadData = data => { 11 | let arr = []; 12 | for (const key in data) { 13 | let firstKey = Object.keys(data[key])[0]; 14 | arr.push(data[key][firstKey]) 15 | } 16 | return arr 17 | }; 18 | 19 | module.exports = async (files) => { 20 | 21 | if ( 22 | OPADS_URL === 'YOUR OPADS URL' || 23 | OPADS_PROJECT === 'YOUR OPADS PROJECT' || 24 | OPADS_AUTHKEY === 'YOUR OPADS AUTHKEY' 25 | ) { 26 | throw { status: 404, name: 'UPLOAD_ERROR_CONFIG', message: '请在 process.env 里配置 opads 上传相关的配置:OPADS_URL/OPADS_PROJECT/OPADS_AUTHKEY' }; 27 | } 28 | 29 | let uploadObj = {} 30 | 31 | files.forEach((file, key) => { 32 | uploadObj[`Upload[file${key}]`] = file; 33 | uploadObj[`FileName[file${key}]`] = `piper/${file.path}` 34 | }) 35 | 36 | var options = { 37 | url: OPADS_URL, 38 | json: true, 39 | formData: Object.assign({ 40 | project: OPADS_PROJECT, 41 | authkey: OPADS_AUTHKEY 42 | }, uploadObj) 43 | }; 44 | 45 | try { 46 | let uploadRes = await request.post(options); 47 | if(uploadRes.code == 0) { 48 | return getUploadData(uploadRes.data) 49 | } else { 50 | throw { status: 404, name: 'UPLOAD_ERROR_' + uploadRes.code, message: uploadRes.msg }; 51 | } 52 | } catch(e) { 53 | throw { status: 404, name: 'UPLOAD_ERROR', message: 'upload error' }; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /server/lib/publish/qiniu.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const _ = require('lodash') 3 | const qiniu = require('qiniu') 4 | 5 | let { 6 | QINIU_ACCESS_KEY, 7 | QINIU_SECRET_KEY, 8 | QINIU_BUCKET, 9 | QINIU_BASEURL 10 | } = process.env; 11 | 12 | qiniu.conf.ACCESS_KEY = QINIU_ACCESS_KEY; 13 | qiniu.conf.SECRET_KEY = QINIU_SECRET_KEY; 14 | 15 | const getUptoken = (key) => { 16 | if (_.isEmpty(key)) return 17 | 18 | const putPolicy = new qiniu.rs.PutPolicy(`${QINIU_BUCKET}:${key}`) 19 | return putPolicy.token() 20 | } 21 | 22 | const upload = (uptoken, localFile) => { 23 | 24 | if (_.isEmpty(uptoken)) return 25 | 26 | const extra = new qiniu.io.PutExtra() 27 | 28 | return new Promise((resolve, reject) => { 29 | qiniu.io.putFile(uptoken, localFile, localFile, extra, (err, ret) => { 30 | if (!err) { 31 | resolve({ 32 | hash: ret.hash, 33 | key: ret.key, 34 | url: `${QINIU_BASEURL}/${ret.key}` 35 | }) 36 | } else { 37 | console.log("upload error", err, localFile) 38 | reject(err) 39 | } 40 | }) 41 | }) 42 | } 43 | 44 | module.exports = async (files) => { 45 | 46 | if ( 47 | QINIU_ACCESS_KEY === 'YOUR QINIU AK' || 48 | QINIU_SECRET_KEY === 'YOUR QINIU SK' || 49 | QINIU_BUCKET === 'YOUR QINIU BUCKET' || 50 | QINIU_BASEURL === 'YOUR QINIU URL' 51 | ) { 52 | throw { status: 404, name: 'UPLOAD_ERROR_CONFIG', message: '请在 process.env 里配置 qiniu 上传相关的配置: QINIU_ACCESS_KEY/QINIU_SECRET_KEY/QINIU_BUCKET/QINIU_BASEURL' }; 53 | } 54 | 55 | let tasks = files.map((file, key) => upload(getUptoken(file.path), file.path)); 56 | 57 | return await Promise.all(tasks); 58 | } 59 | -------------------------------------------------------------------------------- /server/models/changelog.js: -------------------------------------------------------------------------------- 1 | /* jshint indent: 2 */ 2 | 3 | module.exports = function(sequelize, DataTypes) { 4 | let changelog = sequelize.define('changelog', { 5 | id: { 6 | type: DataTypes.INTEGER(11), 7 | allowNull: false, 8 | primaryKey: true, 9 | autoIncrement: true 10 | }, 11 | action: { 12 | type: DataTypes.INTEGER(4), 13 | allowNull: false, 14 | defaultValue: '0' 15 | }, 16 | page_id: { 17 | type: DataTypes.INTEGER(11), 18 | allowNull: false 19 | }, 20 | items: { 21 | type: DataTypes.STRING(10240), 22 | allowNull: true, 23 | defaultValue: '' 24 | }, 25 | create_by: { 26 | type: DataTypes.INTEGER(11), 27 | allowNull: false, 28 | defaultValue: '0' 29 | } 30 | }, { 31 | tableName: 'changelog' 32 | }); 33 | 34 | changelog.associate = function(models) { 35 | changelog.belongsTo(models.pages, {foreignKey: 'page_id'}); 36 | changelog.belongsTo(models.users, {foreignKey: 'create_by'}); 37 | } 38 | 39 | return changelog; 40 | }; 41 | -------------------------------------------------------------------------------- /server/models/index.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const fs = require("fs"); 3 | const path = require("path"); 4 | const Sequelize = require('sequelize'); 5 | const env = process.env.NODE_ENV || "development"; 6 | const config = require(path.join(__dirname, '../../', 'config', 'db.js'))[env]; 7 | 8 | const params = Object.assign({ 9 | // 字段以下划线(_)来分割 10 | underscored: true, 11 | dialectOptions: { 12 | ssl: false 13 | }, 14 | define: { 15 | timestamps: true, 16 | createdAt: 'create_at', 17 | updatedAt: 'update_at' 18 | }, 19 | // logging: false 20 | }, config); 21 | 22 | let sequelize 23 | 24 | if (config.url) { 25 | sequelize = new Sequelize(config.url, params); 26 | } else { 27 | sequelize = new Sequelize(config.database, config.username, config.password, params); 28 | } 29 | 30 | let db = {}; 31 | 32 | fs 33 | .readdirSync(__dirname) 34 | .filter(function(file) { 35 | return (file.indexOf(".") !== 0) && (file !== "index.js"); 36 | }) 37 | .forEach(function(file) { 38 | var model = sequelize.import(path.join(__dirname, file)); 39 | db[model.name] = model; 40 | }); 41 | 42 | Object.keys(db).forEach(function(modelName) { 43 | if ("associate" in db[modelName]) { 44 | db[modelName].associate(db); 45 | } 46 | }); 47 | 48 | db.sequelize = sequelize; 49 | db.Sequelize = Sequelize; 50 | 51 | module.exports = db; 52 | -------------------------------------------------------------------------------- /server/models/pages.js: -------------------------------------------------------------------------------- 1 | /* jshint indent: 2 */ 2 | 3 | module.exports = function(sequelize, DataTypes) { 4 | let pages = sequelize.define('pages', { 5 | id: { 6 | type: DataTypes.INTEGER(11), 7 | allowNull: false, 8 | primaryKey: true, 9 | autoIncrement: true 10 | }, 11 | title: { 12 | type: DataTypes.STRING(64), 13 | allowNull: false 14 | }, 15 | cover: { 16 | type: DataTypes.STRING(64), 17 | allowNull: true, 18 | defaultValue: '' 19 | }, 20 | config: { 21 | type: DataTypes.STRING(512), 22 | allowNull: false, 23 | defaultValue: '' 24 | }, 25 | items: { 26 | type: DataTypes.STRING(10240), 27 | allowNull: false 28 | }, 29 | create_by: { 30 | type: DataTypes.INTEGER(11), 31 | allowNull: false, 32 | defaultValue: '0' 33 | }, 34 | is_publish: { 35 | type: DataTypes.INTEGER(4), 36 | allowNull: false, 37 | defaultValue: '0' 38 | }, 39 | is_delete: { 40 | type: DataTypes.INTEGER(4), 41 | allowNull: false, 42 | defaultValue: '0' 43 | }, 44 | publish_at: { 45 | type: DataTypes.DATE, 46 | allowNull: true, 47 | defaultValue: sequelize.NOW 48 | } 49 | }, { 50 | tableName: 'pages' 51 | }); 52 | 53 | pages.associate = function(models) { 54 | pages.hasOne(models.changelog, {foreignKey: 'page_id'}); 55 | pages.belongsTo(models.users, {foreignKey: 'create_by'}); 56 | } 57 | 58 | return pages; 59 | }; 60 | -------------------------------------------------------------------------------- /server/models/users.js: -------------------------------------------------------------------------------- 1 | /* jshint indent: 2 */ 2 | 3 | module.exports = function(sequelize, DataTypes) { 4 | let users = sequelize.define('users', { 5 | id: { 6 | type: DataTypes.INTEGER(11), 7 | allowNull: false, 8 | primaryKey: true, 9 | autoIncrement: true 10 | }, 11 | name: { 12 | type: DataTypes.STRING(64), 13 | allowNull: false 14 | }, 15 | email: { 16 | type: DataTypes.STRING(64), 17 | allowNull: false 18 | }, 19 | github_id: { 20 | type: DataTypes.INTEGER(11), 21 | allowNull: false, 22 | defaultValue: '0' 23 | }, 24 | avatar: { 25 | type: DataTypes.STRING(64), 26 | allowNull: true, 27 | defaultValue: '', 28 | } 29 | }, { 30 | tableName: 'users' 31 | }); 32 | 33 | users.associate = function(models) { 34 | users.hasOne(models.changelog, {foreignKey: 'create_by'}); 35 | users.hasOne(models.pages, {foreignKey: 'create_by'}); 36 | } 37 | 38 | return users; 39 | }; 40 | -------------------------------------------------------------------------------- /server/views/activity.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= page.title %> 9 | 12 | 13 | 14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 9 | 78 | 93 | -------------------------------------------------------------------------------- /src/api/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import axios from 'axios' 3 | import { Message } from 'element-ui' 4 | import store from '../store' 5 | 6 | let logoutMessageShown = false 7 | 8 | axios.defaults.baseURL = '/api'; 9 | 10 | // loading bar 11 | const loadTimer = [] 12 | const showLoading = (bool) => { 13 | if (bool) { 14 | loadTimer.push(setTimeout(() => { 15 | store.commit('CHANGE_LOADING_BAR', true) 16 | }, 100)) 17 | } else { 18 | clearTimeout(loadTimer.splice(0, 1)) 19 | store.commit('CHANGE_LOADING_BAR', false) 20 | } 21 | } 22 | 23 | // Add a request interceptor 24 | axios.interceptors.request.use(function (config) { 25 | showLoading(true) 26 | return config 27 | }, function (error) { 28 | showLoading(false) 29 | return Promise.reject(error) 30 | }) 31 | 32 | // Add a response interceptor 33 | axios.interceptors.response.use(function (response) { 34 | showLoading(false) 35 | // TODO 全局api错误处理 36 | return response 37 | }, function (error) { 38 | showLoading(false) 39 | // 网络异常处理 40 | if (error.response.status == 500){ 41 | Message({ 42 | type: 'error', 43 | message: error.response.data.message, 44 | duration: 0, 45 | showClose: true 46 | }); 47 | } else if (error.response.status == 401 && !logoutMessageShown){ 48 | logoutMessageShown = true 49 | Message.error('登录失效,请重新登录'); 50 | store.dispatch('redirectLogin') 51 | } else { 52 | error.response.data && error.response.data.message && Message.error(error.response.data.message); 53 | } 54 | 55 | return Promise.reject(error) 56 | }) 57 | 58 | export default { 59 | page: { 60 | getData(id) { 61 | return axios 62 | .get('page/'+id) 63 | }, 64 | updateData(id, data) { 65 | return axios 66 | .put('page/'+id, data) 67 | }, 68 | /** 69 | * 保存 design 70 | * @returns {*} 71 | */ 72 | saveData(data) { 73 | return axios 74 | .put('pages', data) 75 | }, 76 | removeData(id) { 77 | return axios 78 | .delete('page/'+id) 79 | } 80 | }, 81 | pages: { 82 | getData(data) { 83 | return axios 84 | .get('pages', { 85 | params: data 86 | }) 87 | } 88 | }, 89 | users: { 90 | getData() { 91 | return axios 92 | .get('users') 93 | } 94 | }, 95 | changelog: { 96 | /** 97 | * 获取所有 changelog 98 | * @returns {*} 99 | */ 100 | getAll(params) { 101 | return axios 102 | .get('changelogs', { 103 | params: params 104 | }) 105 | }, 106 | /** 107 | * 获取最新的 changelog 108 | * @returns {*} 109 | */ 110 | getRecent() { 111 | return axios 112 | .get('changelogs', { 113 | params: { 114 | size: 5, 115 | page: 1 116 | } 117 | }) 118 | } 119 | }, 120 | /** 121 | * 发布项目 122 | * @returns {Promise} 123 | */ 124 | publish(id, data) { 125 | return axios 126 | .put('publish/'+id, data) 127 | }, 128 | /** 129 | * 获取 制作中和已发布 的项目 130 | * @returns {Promise} 131 | */ 132 | count() { 133 | return axios 134 | .get('count') 135 | }, 136 | /** 137 | * 注销 138 | * @returns {Promise} 139 | */ 140 | logout() { 141 | return axios 142 | .get('logout') 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/app.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Element from 'element-ui' 3 | import 'element-ui/lib/theme-default/index.css' 4 | 5 | import store from './store' 6 | import router from './router' 7 | import { sync } from 'vuex-router-sync' 8 | import App from './App.vue' 9 | import ProgressBar from '@/components/ProgressBar' 10 | 11 | import filters from './filters' 12 | 13 | sync(store, router) 14 | 15 | Vue.use(Element) 16 | 17 | Vue.config.productionTip = false 18 | 19 | // ProgressBar 20 | const bar = Vue.prototype.$bar = new Vue(ProgressBar).$mount() 21 | document.body.appendChild(bar.$el) 22 | 23 | router.beforeEach((to, from, next) => { 24 | bar.start() 25 | next() 26 | }) 27 | router.afterEach((to, from) => { 28 | bar.finish() 29 | }) 30 | 31 | // add vue filter 32 | Object.keys(filters).forEach(k => Vue.filter(k, filters[k])); 33 | 34 | const app = new Vue({ 35 | el: '#app', 36 | router, 37 | store, 38 | render: h => h(App) 39 | }) 40 | 41 | // design mode 42 | document.documentElement.classList.add('design-mode') 43 | 44 | export { app, router, store } 45 | -------------------------------------------------------------------------------- /src/assets/img/phone-head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fireyy/piper/55f254709184991d26d37327e6408a9cedfc7654/src/assets/img/phone-head.png -------------------------------------------------------------------------------- /src/assets/img/piper_logo.svg: -------------------------------------------------------------------------------- 1 | piper_logo Created with Sketch. 2 | -------------------------------------------------------------------------------- /src/components/ProgressBar.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 86 | 87 | 101 | -------------------------------------------------------------------------------- /src/components/countdown.vue: -------------------------------------------------------------------------------- 1 | 23 | 145 | 203 | -------------------------------------------------------------------------------- /src/components/ctrl-bar.vue: -------------------------------------------------------------------------------- 1 | 21 | 39 | 90 | -------------------------------------------------------------------------------- /src/components/drag-drop.vue: -------------------------------------------------------------------------------- 1 | 9 | 26 | 110 | -------------------------------------------------------------------------------- /src/components/drag-move.vue: -------------------------------------------------------------------------------- 1 | 6 | 14 | 117 | -------------------------------------------------------------------------------- /src/components/header.vue: -------------------------------------------------------------------------------- 1 | 28 | 58 | 121 | -------------------------------------------------------------------------------- /src/components/index.js: -------------------------------------------------------------------------------- 1 | export default { 2 | loading : require('./loading.vue'), 3 | ctrlBar : require('./ctrl-bar.vue') 4 | } 5 | -------------------------------------------------------------------------------- /src/components/loading.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 12 | 13 | 26 | -------------------------------------------------------------------------------- /src/components/module-container.vue: -------------------------------------------------------------------------------- 1 | 21 | 75 | 121 | -------------------------------------------------------------------------------- /src/components/preview.vue: -------------------------------------------------------------------------------- 1 | 8 | 13 | 37 | 38 | -------------------------------------------------------------------------------- /src/components/property.vue: -------------------------------------------------------------------------------- 1 | 23 | 59 | 85 | -------------------------------------------------------------------------------- /src/components/qrcode.vue: -------------------------------------------------------------------------------- 1 | 12 | 83 | -------------------------------------------------------------------------------- /src/components/render.vue: -------------------------------------------------------------------------------- 1 | 35 | 146 | 228 | -------------------------------------------------------------------------------- /src/components/swiper/index.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 169 | 170 | 265 | -------------------------------------------------------------------------------- /src/components/swiper/swiper-item.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 18 | -------------------------------------------------------------------------------- /src/components/swiper/swiper.js: -------------------------------------------------------------------------------- 1 | import objectAssign from 'object-assign' 2 | 3 | class Swiper { 4 | constructor (options) { 5 | this._default = { 6 | container: '.piper-swiper', 7 | item: '.piper-swiper-item', 8 | direction: 'vertical', 9 | activeClass: 'active', 10 | threshold: 50, 11 | duration: 300, 12 | auto: false, 13 | loop: false, 14 | interval: 3000, 15 | height: 'auto', 16 | minMovingDistance: 0 17 | } 18 | this._options = objectAssign(this._default, options) 19 | this._options.height = this._options.height.replace('px', '') 20 | this._start = {} 21 | this._move = {} 22 | this._end = {} 23 | this._eventHandlers = {} 24 | this._prev = this._current = this._goto = 0 25 | this._width = this._height = this._distance = 0 26 | this._offset = [] 27 | this.$box = this._options.container 28 | this.$container = this._options.container.querySelector('.piper-swiper') 29 | this.$items = this.$container.querySelectorAll(this._options.item) 30 | this.count = this.$items.length 31 | this.realCount = this.$items.length // real items length 32 | this._position = [] // used by go event 33 | this._firstItemIndex = 0 34 | if (!this.count) { 35 | return 36 | } 37 | this._init() 38 | this._auto() 39 | this._bind() 40 | this._onResize() 41 | return this 42 | } 43 | 44 | _auto () { 45 | const me = this 46 | me.stop() 47 | if (me._options.auto) { 48 | me.timer = setTimeout(() => { 49 | me.next() 50 | }, me._options.interval) 51 | } 52 | } 53 | 54 | updateItemWidth () { 55 | this._width = this.$box.offsetWidth 56 | this._distance = this._options.direction === 'horizontal' ? this._width : this._height 57 | } 58 | 59 | stop () { 60 | this.timer && clearTimeout(this.timer) 61 | } 62 | 63 | _loop () { 64 | return this._options.loop && this.realCount >= 3 65 | } 66 | 67 | _onResize () { 68 | const me = this 69 | this.resizeHandler = () => { 70 | setTimeout(() => { 71 | me.updateItemWidth() 72 | me._setOffset() 73 | me._setTransfrom() 74 | }, 100) 75 | } 76 | window.addEventListener('orientationchange', this.resizeHandler, false) 77 | } 78 | 79 | _init () { 80 | if (this._options.loop) { 81 | this._loopTwoItems() 82 | } 83 | this._height = this._options.height === 'auto' ? 'auto' : this._options.height - 0 84 | this.updateItemWidth() 85 | this._initPosition() 86 | this._activate(this._current) 87 | this._setOffset() 88 | this._setTransfrom() 89 | if (this._loop()) { 90 | this._loopRender() 91 | } 92 | } 93 | 94 | _initPosition () { 95 | for (let i = 0; i < this.realCount; i++) { 96 | this._position.push(i) 97 | } 98 | } 99 | 100 | _movePosition (position) { 101 | const me = this 102 | if (position > 0) { 103 | let firstIndex = me._position.splice(0, 1) 104 | me._position.push(firstIndex[0]) 105 | } else if (position < 0) { 106 | let lastIndex = me._position.pop() 107 | me._position.unshift(lastIndex) 108 | } 109 | } 110 | 111 | _setOffset () { 112 | let me = this 113 | let index = me._position.indexOf(me._current) 114 | me._offset = [] 115 | Array.prototype.forEach.call(me.$items, function ($item, key) { 116 | me._offset.push((key - index) * me._distance) 117 | }) 118 | } 119 | 120 | _setTransition (duration) { 121 | duration = duration || (this._options.duration || 'none') 122 | let transition = duration === 'none' ? 'none' : duration + 'ms' 123 | Array.prototype.forEach.call(this.$items, function ($item, key) { 124 | $item.style.webkitTransition = transition 125 | $item.style.transition = transition 126 | }) 127 | } 128 | 129 | _setTransfrom (offset) { 130 | const me = this 131 | offset = offset || 0 132 | Array.prototype.forEach.call(me.$items, function ($item, key) { 133 | let distance = me._offset[key] + offset 134 | let transform = `translate3d(${distance}px, 0, 0)` 135 | if (me._options.direction === 'vertical') { 136 | transform = `translate3d(0, ${distance}px, 0)` 137 | } 138 | $item.style.webkitTransform = transform 139 | $item.style.transform = transform 140 | }) 141 | } 142 | 143 | _bind () { 144 | const me = this 145 | me.touchstartHandler = (e) => { 146 | me.stop() 147 | me._start.x = e.changedTouches[0].pageX 148 | me._start.y = e.changedTouches[0].pageY 149 | me._setTransition('none') 150 | } 151 | me.touchmoveHandler = (e) => { 152 | me._move.x = e.changedTouches[0].pageX 153 | me._move.y = e.changedTouches[0].pageY 154 | let distanceX = me._move.x - me._start.x 155 | let distanceY = me._move.y - me._start.y 156 | let distance = distanceY 157 | let noScrollerY = Math.abs(distanceX) > Math.abs(distanceY) 158 | if (me._options.direction === 'horizontal' && noScrollerY) { 159 | distance = distanceX 160 | } 161 | if (((me._options.minMovingDistance && Math.abs(distance) >= me._options.minMovingDistance) || !me._options.minMovingDistance) && noScrollerY) { 162 | me._setTransfrom(distance) 163 | } 164 | 165 | noScrollerY && e.preventDefault() 166 | } 167 | 168 | me.touchendHandler = (e) => { 169 | me._end.x = e.changedTouches[0].pageX 170 | me._end.y = e.changedTouches[0].pageY 171 | 172 | let distance = me._end.y - me._start.y 173 | if (me._options.direction === 'horizontal') { 174 | distance = me._end.x - me._start.x 175 | } 176 | 177 | distance = me.getDistance(distance) 178 | if (distance !== 0 && me._options.minMovingDistance && Math.abs(distance) < me._options.minMovingDistance) { 179 | return 180 | } 181 | if (distance > me._options.threshold) { 182 | me.move(-1) 183 | } else if (distance < -me._options.threshold) { 184 | me.move(1) 185 | } else { 186 | me.move(0) 187 | } 188 | 189 | me._loopRender() 190 | } 191 | 192 | me.transitionEndHandler = (e) => { 193 | me._activate(me._current) 194 | let cb = me._eventHandlers.swiped 195 | cb && cb.apply(me, [me._prev % me.count, me._current % me.count]) 196 | me._auto() 197 | me._loopRender() 198 | e.preventDefault() 199 | } 200 | me.$container.addEventListener('touchstart', me.touchstartHandler, false) 201 | me.$container.addEventListener('touchmove', me.touchmoveHandler, false) 202 | me.$container.addEventListener('touchend', me.touchendHandler, false) 203 | me.$items[1] && me.$items[1].addEventListener('webkitTransitionEnd', me.transitionEndHandler, false) 204 | } 205 | 206 | _loopTwoItems () { 207 | // issue #596 (support when onlt two) 208 | if (this.count === 2) { 209 | let div = document.createElement('div') 210 | let $item 211 | for (let i = this.$items.length - 1; i >= 0; i--) { 212 | div.innerHTML = this.$items[i].outerHTML 213 | $item = div.querySelector(this._options.item) 214 | $item.classList.add(`${this._options.item.replace('.', '')}-clone`) 215 | this.$container.appendChild($item) 216 | } 217 | this.realCount = 4 218 | } 219 | } 220 | 221 | _loopRender () { 222 | const me = this 223 | if (me._loop()) { 224 | // issue #507 (delete cloneNode) 225 | if (me._offset[me._offset.length - 1] === 0) { 226 | me.$container.appendChild(me.$items[0]) 227 | me._loopEvent(1) 228 | } else if (me._offset[0] === 0) { 229 | me.$container.insertBefore(me.$items[me.$items.length - 1], me.$container.firstChild) 230 | me._loopEvent(-1) 231 | } 232 | } 233 | } 234 | 235 | _loopEvent (num) { 236 | const me = this 237 | me._itemDestoy() 238 | me.$items = me.$container.querySelectorAll(me._options.item) 239 | me.$items[1] && me.$items[1].addEventListener('webkitTransitionEnd', me.transitionEndHandler, false) 240 | me._movePosition(num) 241 | me._setOffset() 242 | me._setTransfrom() 243 | } 244 | 245 | getDistance (distance) { 246 | if (this._loop()) { 247 | return distance 248 | } else { 249 | if (distance > 0 && this._current === 0) { 250 | return 0 251 | } else if (distance < 0 && this._current === this.realCount - 1) { 252 | return 0 253 | } else { 254 | return distance 255 | } 256 | } 257 | } 258 | 259 | _moveIndex (num) { 260 | if (num !== 0) { 261 | this._prev = this._current 262 | this._current += this.realCount 263 | this._current += num 264 | this._current %= this.realCount 265 | } 266 | } 267 | 268 | _activate (index) { 269 | let clazz = this._options.activeClass 270 | Array.prototype.forEach.call(this.$items, ($item, key) => { 271 | $item.classList.remove(clazz) 272 | if (index === Number($item.dataset.index)) { 273 | $item.classList.add(clazz) 274 | } 275 | }) 276 | } 277 | 278 | go (index) { 279 | const me = this 280 | me.stop() 281 | 282 | index = index || 0 283 | index += this.realCount 284 | index = index % this.realCount 285 | index = this._position.indexOf(index) - this._position.indexOf(this._current) 286 | 287 | me._moveIndex(index) 288 | me._setOffset() 289 | me._setTransition() 290 | me._setTransfrom() 291 | me._auto() 292 | return this 293 | } 294 | 295 | next () { 296 | this.move(1) 297 | return this 298 | } 299 | 300 | move (num) { 301 | this.go(this._current + num) 302 | return this 303 | } 304 | 305 | on (event, callback) { 306 | if (this._eventHandlers[event]) { 307 | console.error(`[swiper] event ${event} is already register`) 308 | } 309 | if (typeof callback !== 'function') { 310 | console.error('[swiper] parameter callback must be a function') 311 | } 312 | this._eventHandlers[event] = callback 313 | return this 314 | } 315 | 316 | _itemDestoy () { 317 | for (let i = this.$items.length - 1; i >= 0; i--) { 318 | this.$items[i].removeEventListener('webkitTransitionEnd', this.transitionEndHandler, false) 319 | } 320 | } 321 | destroy () { 322 | this.stop() 323 | this._current = 0 324 | this._setTransfrom(0) 325 | window.removeEventListener('orientationchange', this.resizeHandler, false) 326 | this.$container.removeEventListener('touchstart', this.touchstartHandler, false) 327 | this.$container.removeEventListener('touchmove', this.touchmoveHandler, false) 328 | this.$container.removeEventListener('touchend', this.touchendHandler, false) 329 | this._itemDestoy() 330 | // remove clone item (used by loop only 2) 331 | if (this._options.loop && this.count === 2) { 332 | let $item = this.$container.querySelector(`${this._options.item}-clone`) 333 | $item && this.$container.removeChild($item) 334 | $item = this.$container.querySelector(`${this._options.item}-clone`) 335 | $item && this.$container.removeChild($item) 336 | } 337 | } 338 | } 339 | 340 | export default Swiper 341 | -------------------------------------------------------------------------------- /src/constants/default.js: -------------------------------------------------------------------------------- 1 | export default { 2 | style: { 3 | type: 'htmlStyle', 4 | title: '样式', 5 | value: { 6 | color: { 7 | type: "inputColor", 8 | value: "#c8c58a" 9 | }, 10 | backgroundColor: { 11 | type: "inputColor", 12 | value: "#fffbcb" 13 | }, 14 | backgroundImage: { 15 | type: "inputImage", 16 | value: null 17 | } 18 | } 19 | }, 20 | shareTitle: { 21 | type: 'inputText', 22 | value: '测试文字' 23 | }, 24 | shareLink: { 25 | type: 'inputText', 26 | value: 'http://' 27 | }, 28 | shareContent: { 29 | type: 'inputTextarea', 30 | value: '测试文字' 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/constants/lang.js: -------------------------------------------------------------------------------- 1 | export default { 2 | action1: '创建', 3 | action2: '更新', 4 | action3: '删除', 5 | action4: '发布', 6 | time: '时间范围', 7 | image: '图片', 8 | content: '内容', 9 | color: '文字颜色', 10 | backgroundColor: '背景色', 11 | backgroundImage: '背景图片', 12 | textAlign: '对齐方式', 13 | padding: '内边距', 14 | margin: '外边距', 15 | height: '高度', 16 | link: '链接', 17 | shareTitle: '分享标题', 18 | shareLink: '分享链接', 19 | shareContent: '分享内容', 20 | wheel: ['上','右','下','左'], 21 | font: '文字样式' 22 | } 23 | -------------------------------------------------------------------------------- /src/constants/props.js: -------------------------------------------------------------------------------- 1 | export default { 2 | align: [ 3 | { 4 | title: "左", 5 | value: 'left' 6 | }, 7 | { 8 | title: "中", 9 | value: 'center' 10 | }, 11 | { 12 | title: "右", 13 | value: 'right' 14 | } 15 | ], 16 | 'btn-theme': [ 17 | { 18 | title: "默认", 19 | value: '' 20 | }, 21 | { 22 | title: "主要", 23 | value: 'primary' 24 | }, 25 | { 26 | title: "透明", 27 | value: 'blank' 28 | } 29 | ], 30 | 'btn-size': [ 31 | { 32 | title: "默认", 33 | value: '' 34 | }, 35 | { 36 | title: "小", 37 | value: 'sm' 38 | }, 39 | { 40 | title: "超小", 41 | value: 'xs' 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /src/constants/rules.js: -------------------------------------------------------------------------------- 1 | export default { 2 | content: [ 3 | { required: true, message: '请输入内容', trigger: 'blur' }, 4 | { min: 1, max: 20, message: '长度在 1-20 个字符', trigger: 'blur' } 5 | ], 6 | link: [ 7 | { type: 'url', required: true, message: '请输入链接', trigger: 'blur' } 8 | ], 9 | time: [ 10 | { required: true, message: '请选择时间', trigger: 'blur' } 11 | ], 12 | timerange: [ 13 | { type: 'array', required: true, message: '请选择时间', trigger: 'blur' } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/filters/index.js: -------------------------------------------------------------------------------- 1 | import lang from '../constants/lang' 2 | 3 | export default { 4 | formatDate(value) { 5 | let options = {} 6 | return new Date(value).toLocaleString('zh-CN', options) 7 | }, 8 | lang(value) { 9 | return lang[value] || value 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/modules/btn.vue: -------------------------------------------------------------------------------- 1 | 6 | 47 | 66 | -------------------------------------------------------------------------------- /src/modules/countdown.vue: -------------------------------------------------------------------------------- 1 | 7 | 30 | -------------------------------------------------------------------------------- /src/modules/index.js: -------------------------------------------------------------------------------- 1 | export const modules = [ 2 | { 3 | title: '常规', 4 | items: [ 5 | { 6 | alias: '相对定位', 7 | type: 'relative', 8 | icon: 'menu', //from http://element.eleme.io/#/zh-CN/component/icon 9 | children: [], 10 | data: { 11 | style: { 12 | type: 'htmlStyle', 13 | title: '样式', 14 | value: { 15 | height: { 16 | type: "inputNumber", 17 | value: "300px" 18 | } 19 | } 20 | } 21 | }, 22 | component: require('./relative.vue') 23 | }, 24 | { 25 | alias: '文本', 26 | type: 'txt', 27 | icon: 'edit', 28 | data: { 29 | content: { 30 | type: 'inputTextarea', 31 | value: '测试文字' 32 | }, 33 | style: { 34 | type: 'htmlStyle', 35 | title: '样式', 36 | value: { 37 | textAlign: { 38 | type: "inputRadio", 39 | props: 'align', 40 | value: 'center' 41 | }, 42 | font: { 43 | type: "inputFont", 44 | value: "normal normal 12px sans-serif" 45 | }, 46 | color: { 47 | type: "inputColor", 48 | value: "#ffffff" 49 | }, 50 | backgroundColor: { 51 | type: "inputColor", 52 | value: "#ff0000" 53 | }, 54 | padding: { 55 | type: "inputWheel", 56 | value: "0 0 0 0" 57 | }, 58 | margin: { 59 | type: "inputWheel", 60 | value: "0 0 0 0" 61 | } 62 | } 63 | } 64 | }, 65 | component: require('./txt.vue') 66 | }, 67 | { 68 | alias: '按钮', 69 | type: 'btn', 70 | icon: 'minus', 71 | style: { 72 | "top" : "20px", 73 | "left" : "20px" 74 | }, 75 | data: { 76 | content: { 77 | type: 'inputText', 78 | title: '按钮文字', 79 | rule: { 80 | type: 'text' 81 | }, 82 | value: '按钮' 83 | }, 84 | size: { 85 | type: 'inputRadio', 86 | title: '按钮文字', 87 | props: 'btn-size', 88 | value: '' 89 | }, 90 | theme: { 91 | type: 'inputRadio', 92 | title: '按钮颜色', 93 | props: 'btn-theme', 94 | value: '' 95 | } 96 | }, 97 | component: require('./btn.vue') 98 | } 99 | ] 100 | }, 101 | { 102 | title: '图片', 103 | items: [ 104 | { 105 | alias: '图片', 106 | type: 'poster', 107 | icon: 'picture', 108 | data: { 109 | pic: { 110 | type: 'group', 111 | title: '图片', 112 | value: [ 113 | { 114 | 'link': { 115 | type: 'inputText', 116 | value: null, 117 | }, 118 | 'image': { 119 | type: 'inputImage', 120 | value: 'http://img1.ffan.com/T1xEWTBmET1RCvBVdK' 121 | } 122 | } 123 | ], 124 | options: { 125 | max: 1 126 | } 127 | } 128 | }, 129 | component: require('./poster.vue') 130 | }, 131 | { 132 | alias: '幻灯片', 133 | type: 'swipe', 134 | icon: 'picture', 135 | data: { 136 | pic: { 137 | type: 'group', 138 | title: '幻灯片', 139 | value: [ 140 | { 141 | 'link': { 142 | type: 'inputText', 143 | value: null, 144 | }, 145 | 'image': { 146 | type: 'inputImage', 147 | value: 'http://img1.ffan.com/T14.CTB4LT1RCvBVdK' 148 | } 149 | }, 150 | { 151 | 'link': { 152 | type: 'inputText', 153 | value: null, 154 | }, 155 | 'image': { 156 | type: 'inputImage', 157 | value: 'http://img1.ffan.com/T1xEWTBmET1RCvBVdK' 158 | } 159 | } 160 | ], 161 | options: { 162 | max: 4 163 | } 164 | } 165 | }, 166 | component: require('./swipe.vue') 167 | } 168 | ] 169 | }, 170 | { 171 | title: '其他', 172 | items: [ 173 | { 174 | alias: '倒计时', 175 | type: 'countdown', 176 | icon: 'time', 177 | data: { 178 | time: { 179 | type: 'inputDate', 180 | sub: 'datetimerange', 181 | rule: 'timerange', 182 | value: [] 183 | } 184 | }, 185 | component: require('./countdown.vue') 186 | } 187 | ] 188 | } 189 | ] 190 | 191 | export let components = {}; 192 | modules.forEach(function(obj){ 193 | if(obj.items && obj.items.length > 0) { 194 | obj.items.forEach(function(item){ 195 | components[item.type] = item.component 196 | }) 197 | } 198 | }); 199 | -------------------------------------------------------------------------------- /src/modules/poster.vue: -------------------------------------------------------------------------------- 1 | 18 | 29 | 40 | -------------------------------------------------------------------------------- /src/modules/relative.vue: -------------------------------------------------------------------------------- 1 | 8 | 13 | 27 | -------------------------------------------------------------------------------- /src/modules/swipe.vue: -------------------------------------------------------------------------------- 1 | 18 | 47 | -------------------------------------------------------------------------------- /src/modules/txt.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 25 | -------------------------------------------------------------------------------- /src/preview.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import './skin/dpi.less' 3 | import Preview from './views/Preview.vue' 4 | 5 | const preview = new Vue({ 6 | el: '#preview', 7 | render: h => h(Preview) 8 | }) 9 | -------------------------------------------------------------------------------- /src/property/common.js: -------------------------------------------------------------------------------- 1 | import { mapActions } from 'vuex' 2 | import rules from '../constants/rules' 3 | export default { 4 | props: { 5 | data: { 6 | type: Object 7 | }, 8 | title: String, 9 | index: [String, Number] 10 | }, 11 | computed: { 12 | label() { 13 | return this.data.title || this.title 14 | }, 15 | prop() { 16 | return this.index 17 | } 18 | }, 19 | methods: { 20 | ...mapActions([ 21 | 'editModuleData' 22 | ]) 23 | }, 24 | watch: { 25 | 'data': { 26 | deep: true, 27 | handler: function(newVal, oldVal) { 28 | if(!newVal) return 29 | 30 | this.editModuleData(newVal) 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/property/group.vue: -------------------------------------------------------------------------------- 1 | 11 | 38 | 69 | -------------------------------------------------------------------------------- /src/property/html-style.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 22 | -------------------------------------------------------------------------------- /src/property/index.js: -------------------------------------------------------------------------------- 1 | import inputs from './input' 2 | 3 | export default { 4 | ...inputs, 5 | group : require('./group.vue'), 6 | htmlStyle : require('./html-style.vue') 7 | } 8 | -------------------------------------------------------------------------------- /src/property/input-checkbox.vue: -------------------------------------------------------------------------------- 1 | 8 | 25 | -------------------------------------------------------------------------------- /src/property/input-color.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 13 | -------------------------------------------------------------------------------- /src/property/input-date.vue: -------------------------------------------------------------------------------- 1 | 14 | 33 | -------------------------------------------------------------------------------- /src/property/input-font.vue: -------------------------------------------------------------------------------- 1 | 17 | 93 | 107 | -------------------------------------------------------------------------------- /src/property/input-image.vue: -------------------------------------------------------------------------------- 1 | 28 | 46 | 84 | -------------------------------------------------------------------------------- /src/property/input-number.vue: -------------------------------------------------------------------------------- 1 | 10 | 34 | -------------------------------------------------------------------------------- /src/property/input-radio.vue: -------------------------------------------------------------------------------- 1 | 8 | 25 | -------------------------------------------------------------------------------- /src/property/input-text.vue: -------------------------------------------------------------------------------- 1 | 6 | 18 | -------------------------------------------------------------------------------- /src/property/input-textarea.vue: -------------------------------------------------------------------------------- 1 | 6 | 18 | -------------------------------------------------------------------------------- /src/property/input-wheel.vue: -------------------------------------------------------------------------------- 1 | 15 | 69 | 130 | -------------------------------------------------------------------------------- /src/property/input.js: -------------------------------------------------------------------------------- 1 | export default { 2 | inputText : require('./input-text.vue'), 3 | inputTextarea : require('./input-textarea.vue'), 4 | inputColor : require('./input-color.vue'), 5 | inputRadio : require('./input-radio.vue'), 6 | inputImage : require('./input-image.vue'), 7 | inputDate : require('./input-date.vue'), 8 | inputWheel : require('./input-wheel.vue'), 9 | inputCheckbox : require('./input-checkbox.vue'), 10 | inputFont : require('./input-font.vue'), 11 | inputNumber : require('./input-number.vue') 12 | } 13 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | 4 | Vue.use(Router) 5 | 6 | // import Login from '../views/Login.vue' 7 | // import Layout from '../views/Layout.vue' 8 | // import Home from '../views/Home.vue' 9 | // import PageList from '../views/PageList.vue' 10 | // import Changelog from '../views/Changelog.vue' 11 | // import Designer from '../views/Designer.vue' 12 | // import UserList from '../views/Users.vue' 13 | 14 | const Login = () => System.import('../views/Login.vue') 15 | const Layout = () => System.import('../views/Layout.vue') 16 | const Home = () => System.import('../views/Home.vue') 17 | const PageList = () => System.import('../views/PageList.vue') 18 | const Changelog = () => System.import('../views/Changelog.vue') 19 | const Designer = () => System.import('../views/Designer.vue') 20 | const Users = () => System.import('../views/Users.vue') 21 | const Preview = () => System.import('../views/Preview.vue') 22 | 23 | export default new Router({ 24 | routes: [ 25 | { 26 | path: '/', 27 | component: Layout, 28 | redirect: { name: 'home' }, 29 | children: [ 30 | { name: 'home', path: '/home', component: Home }, 31 | { 32 | name: 'design', 33 | path: '/design/:id?', 34 | component: Designer 35 | }, 36 | { name: 'pages', path: '/pages', component: PageList }, 37 | { name: 'changelog', path: '/changelog', component: Changelog }, 38 | { name: 'users', path: '/users', component: Users } 39 | ] 40 | }, 41 | { name: 'preview', path: '/preview', component: Preview }, 42 | { name: 'login', path: '/login', component: Login } 43 | ] 44 | }) 45 | -------------------------------------------------------------------------------- /src/skin/_base.less: -------------------------------------------------------------------------------- 1 | @import "_variable"; 2 | 3 | .module-container { 4 | margin-bottom: 20px; 5 | 6 | * { 7 | font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif; 8 | box-sizing: border-box; 9 | } 10 | 11 | a { 12 | text-decoration: none; 13 | display: inline-block; 14 | } 15 | 16 | .color-primary { 17 | color: @color-primary; 18 | } 19 | 20 | .color-default { 21 | color: @color-default; 22 | } 23 | 24 | .color-muted { 25 | color: @color-muted !important; 26 | } 27 | 28 | .text-center { 29 | text-align: center; 30 | } 31 | 32 | .ph-empty { 33 | width: 100%; 34 | color: #aaa; 35 | text-align: center; 36 | padding: 10px 0; 37 | 38 | &.dashed { 39 | border: 1px dashed #ddd; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/skin/_variable.less: -------------------------------------------------------------------------------- 1 | // 主要色调 2 | @color-primary: #FF0400; 3 | @color-default: #555; 4 | @color-muted: #999; 5 | 6 | -------------------------------------------------------------------------------- /src/skin/dpi.less: -------------------------------------------------------------------------------- 1 | // REM 适配 2 | 3 | // 375px (iPhone 6) 4 | // 此为基准值, 与视觉设计稿 `宽度/2` 保持一致 5 | html[data-rem="375"] { 6 | font-size: 20PX; 7 | } 8 | 9 | // 17.06 = 320*20/375 (iPhone 5) 10 | @media only screen and (min-width: 320px) { 11 | html[data-rem="375"] { 12 | font-size: 17.06PX !important; 13 | } 14 | } 15 | 16 | // base root size (iPhone 6) 17 | @media only screen and (min-width: 375px) { 18 | html[data-rem="375"] { 19 | font-size: 20PX !important; 20 | } 21 | } 22 | 23 | // 21.33333333 = 400*20/375 (Most Android) 24 | @media only screen and (min-width: 400px) { 25 | html[data-rem="375"] { 26 | font-size: 21.33333333PX !important; 27 | } 28 | } 29 | 30 | // 22.08 = 414*20/375 (iPhone 6 Plus) 31 | @media only screen and (min-width: 414px) { 32 | html[data-rem="375"] { 33 | font-size: 22.08PX !important; 34 | } 35 | } 36 | 37 | // 25.6 = 480*20/375 (iPad) 38 | @media only screen and (min-width: 480px) { 39 | html[data-rem="375"] { 40 | font-size: 25.6PX !important; 41 | } 42 | } 43 | 44 | // 20*100/375 = 5.333333333 以 375 宽度为基准动态计算 45 | //html[data-rem="375"] { 46 | // font-size: 5.333333333vw; 47 | //} 48 | 49 | // REM 适配, 用法: 50 | 51 | // 320px (iPhone 5) 52 | // 此为基准值, 与视觉设计稿 `宽度/2` 保持一致 53 | html[data-rem="320"] { 54 | font-size: 20PX; 55 | } 56 | 57 | // 23.4375 = 375*20/320 (Most Android) 58 | @media only screen and (min-width: 375px) { 59 | html[data-rem="320"] { 60 | font-size: 23.4375PX !important; 61 | } 62 | } 63 | 64 | // 25 = 400*20/320 (Most Android) 65 | @media only screen and (min-width: 400px) { 66 | html[data-rem="320"] { 67 | font-size: 25PX !important; 68 | } 69 | } 70 | 71 | // 25.875 = 414*20/320 (iPhone 6 Plus) 72 | @media only screen and (min-width: 414px) { 73 | html[data-rem="320"] { 74 | font-size: 25.875PX !important; 75 | } 76 | } 77 | 78 | // 30 = 30 (iPad) 79 | @media only screen and (min-width: 480px) { 80 | html[data-rem="320"] { 81 | font-size: 30PX !important; 82 | } 83 | } 84 | 85 | // 20*100/320 = 6.25 以 320 宽度为基准动态计算 86 | //html[data-rem="320"] { 87 | // font-size: 6.25vw; 88 | //} 89 | -------------------------------------------------------------------------------- /src/store/actions.js: -------------------------------------------------------------------------------- 1 | import * as t from './mutation-types' 2 | import router from '@/router' 3 | 4 | const makeAction = (type) => ( 5 | ({ commit }, payload) => commit(type, payload) 6 | ); 7 | 8 | const makeActions = mutations => ( 9 | Object.keys(mutations).reduce((actions, type) => { 10 | actions[type] = makeAction(normalMutations[type]); 11 | return actions; 12 | }, {}) 13 | ); 14 | 15 | // 可以简单处理的 mutation 16 | const normalMutations = { 17 | addRenderItem: t.ADD_RENDER_ITEM, 18 | editRenderItem: t.EDIT_RENDER_ITEM, 19 | editDragModule: t.EDIT_DRAG_MODULE, 20 | blurRenderItem: t.BLUR_RENDER_ITEM, 21 | focusDocumentTitle: t.FOCUS_DOCUMENT_TITLE, 22 | editDraging: t.EDIT_DRAGING, 23 | editRenderData: t.EDIT_RENDER_DATA, 24 | editModuleData: t.EDIT_MODULE_DATA, 25 | resetRenderState: t.RESET_RENDER_STATE 26 | }; 27 | 28 | // 跳转登录 29 | const redirectLogin = ({ 30 | state 31 | }) => { 32 | router.replace({ path: '/login'}); 33 | } 34 | 35 | const activeRenderItem = ({ 36 | commit 37 | }, event) => { 38 | commit(t.ACTIVE_RENDER_ITEM, getDragInfo(event)) 39 | } 40 | const dropRenderItem = ({ 41 | state, 42 | commit 43 | }, event) => { 44 | let module = state.render.dragModule 45 | let { 46 | dragTag, 47 | position 48 | } = getDragInfo(event) 49 | 50 | if (dragTag) { 51 | let data = module.data || null 52 | 53 | if (dragTag === 'modules') { 54 | commit(t.ADD_RENDER_ITEM, { 55 | type: module.type, 56 | module: module 57 | }) 58 | } else { 59 | let index = +(dragTag.split('-')[1]) 60 | commit(t.ADD_RENDER_ITEM, { 61 | type: module.type, 62 | module: module, 63 | index: position === 'bottom' ? ++index : index, 64 | parent: position === 'inner' ? index : null 65 | }) 66 | } 67 | } 68 | 69 | return dragTag 70 | } 71 | 72 | 73 | /** 74 | * 获得拖拽元素标签和应该出现的位置 75 | * @param event 76 | * @returns {{dragTag: string, position: string}} 77 | */ 78 | function getDragInfo(event) { 79 | let dragTarget = getDragTarget(event.target) 80 | let dragTag = dragTarget && dragTarget.getAttribute('drag-tag') 81 | let position = getDragPosition(event, dragTarget) 82 | 83 | return { 84 | dragTag, 85 | position 86 | } 87 | } 88 | 89 | /** 90 | * 获得拖拽元素的标签名 91 | * @param target 92 | * @returns {string} 93 | */ 94 | function getDragTarget(target) { 95 | let currentNode = target 96 | 97 | while (currentNode) { 98 | if (currentNode.getAttribute && currentNode.getAttribute('drag-tag')) { 99 | return currentNode 100 | } 101 | 102 | currentNode = currentNode.parentNode 103 | } 104 | } 105 | 106 | /** 107 | * 判断拖拽元素应该出现的位置 108 | * @param event 109 | * @param dragTarget 110 | * @returns {string} 111 | */ 112 | function getDragPosition(event, dragTarget) { 113 | if (dragTarget) { 114 | let isDragZone = dragTarget.getAttribute('drag-zone') 115 | let rect = dragTarget.getBoundingClientRect() 116 | let halfHeight = rect.height / 2 117 | 118 | if(isDragZone) { 119 | let position = 'inner', spaceing = 30 120 | 121 | if(event.y - rect.top <= spaceing) { 122 | position = 'top' 123 | } 124 | 125 | if (rect.height - (event.y - rect.top) <= spaceing) { 126 | position = 'bottom' 127 | } 128 | 129 | return position 130 | } else { 131 | return halfHeight > event.y - rect.top ? 'top' : 'bottom' 132 | } 133 | } 134 | } 135 | 136 | export default { 137 | ...makeActions(normalMutations), 138 | activeRenderItem, 139 | dropRenderItem, 140 | redirectLogin 141 | }; 142 | -------------------------------------------------------------------------------- /src/store/getters.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fireyy/piper/55f254709184991d26d37327e6408a9cedfc7654/src/store/getters.js -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | import actions from './actions' 4 | import base from './modules/base' 5 | import render from './modules/render' 6 | 7 | Vue.use(Vuex) 8 | 9 | const store = new Vuex.Store({ 10 | actions, 11 | modules: { 12 | base, 13 | render 14 | } 15 | }) 16 | 17 | export default store 18 | -------------------------------------------------------------------------------- /src/store/modules/base.js: -------------------------------------------------------------------------------- 1 | import { 2 | FOCUS_DOCUMENT_TITLE, 3 | CHANGE_LOADING_BAR 4 | } from '../mutation-types' 5 | 6 | const state = { 7 | activeDocumentTitle: false, 8 | loading: false 9 | } 10 | 11 | const getters = { 12 | base: state => state, 13 | loading: state => state.loading 14 | } 15 | 16 | const mutations = { 17 | [FOCUS_DOCUMENT_TITLE](state, active = true) { 18 | state.activeDocumentTitle = active 19 | }, 20 | [CHANGE_LOADING_BAR](state, loadingBarState) { 21 | state.loading = loadingBarState 22 | } 23 | } 24 | 25 | export default { 26 | state, 27 | getters, 28 | mutations 29 | } 30 | -------------------------------------------------------------------------------- /src/store/modules/render.js: -------------------------------------------------------------------------------- 1 | import _ from "lodash" 2 | import { pick, merge, cloneDeep, flow } from "lodash/fp" 3 | 4 | import { 5 | ACTIVE_RENDER_ITEM, 6 | EDIT_RENDER_ITEM, 7 | ADD_RENDER_ITEM, 8 | BLUR_RENDER_ITEM, 9 | EDIT_DRAG_MODULE, 10 | EDIT_DRAGING, 11 | EDIT_RENDER_DATA, 12 | EDIT_MODULE_DATA, 13 | RESET_RENDER_STATE 14 | } from '../mutation-types' 15 | 16 | import defaultConfig from '@/constants/default' 17 | 18 | const createDefaultState = (data) => { 19 | data.items = [] 20 | data.title = '网页标题' 21 | data.config = _.cloneDeep(defaultConfig) 22 | data.current = {} 23 | data.dragInfo = {} 24 | data.dragModule = {} 25 | data.draging = false 26 | } 27 | 28 | const state = {} 29 | createDefaultState(state) 30 | 31 | const getters = { 32 | activeModules: state => state.dragInfo.dragTag === 'modules', 33 | activeModule: state => state.dragInfo, 34 | currentModule: state => state.current, 35 | dragInfo: state => state.dragInfo, 36 | draging: state => state.draging, 37 | dragModule: state => state.dragModule, 38 | render: state => state, 39 | renderItems: state => state.items 40 | } 41 | 42 | const mutations = { 43 | [ADD_RENDER_ITEM](state, { type, module, index: index = state.items.length + 1, parent: parent = null }) { 44 | 45 | let newItem = flow( 46 | pick(['type', 'alias', 'data', 'children', 'style']), 47 | cloneDeep 48 | )(module) 49 | 50 | // newItem = merge(newItem, { data }) 51 | 52 | newItem._timestamp = newItem._timestamp || Date.now() 53 | 54 | if(parent === null) { 55 | state.items.splice(index, 0, newItem) 56 | } else { 57 | state.items[parent].children.push(newItem) 58 | } 59 | 60 | state.current = newItem 61 | state.dragInfo = {} 62 | }, 63 | 64 | [EDIT_RENDER_ITEM](state, item) { 65 | state.current = item 66 | }, 67 | 68 | [EDIT_MODULE_DATA](state, item) { 69 | let index = state.items.indexOf(item) 70 | if(index !== -1) state.items.splice(index, 1, item) 71 | }, 72 | 73 | [EDIT_RENDER_DATA](state, render) { 74 | if(render.items) state.items = render.items 75 | state.title = render.title 76 | state.config = Object.assign(_.cloneDeep(defaultConfig), render.config || {}) 77 | }, 78 | 79 | [EDIT_DRAG_MODULE](state, dragModule) { 80 | state.dragModule = dragModule 81 | }, 82 | 83 | [EDIT_DRAGING](state, draging) { 84 | state.draging = draging 85 | }, 86 | 87 | [ACTIVE_RENDER_ITEM](state, dragInfo) { 88 | state.dragInfo = dragInfo 89 | }, 90 | 91 | [BLUR_RENDER_ITEM](state) { 92 | state.current = {} 93 | }, 94 | 95 | [RESET_RENDER_STATE](state, store) { 96 | createDefaultState(state) 97 | } 98 | } 99 | 100 | export default { 101 | state, 102 | getters, 103 | mutations 104 | } 105 | -------------------------------------------------------------------------------- /src/store/mutation-types.js: -------------------------------------------------------------------------------- 1 | export const ADD_RENDER_ITEM = 'ADD_RENDER_ITEM' 2 | export const EDIT_RENDER_ITEM = 'EDIT_RENDER_ITEM' 3 | export const ACTIVE_RENDER_ITEM = 'ACTIVE_RENDER_ITEM' 4 | export const BLUR_RENDER_ITEM = 'BLUR_RENDER_ITEM' 5 | export const CHANGE_LOADING_BAR = 'CHANGE_LOADING_BAR' 6 | export const FOCUS_DOCUMENT_TITLE = 'FOCUS_DOCUMENT_TITLE' 7 | export const EDIT_DRAG_MODULE = 'EDIT_DRAG_MODULE' 8 | export const EDIT_DRAGING = 'EDIT_DRAGING' 9 | export const EDIT_RENDER_DATA = 'EDIT_RENDER_DATA' 10 | 11 | export const EDIT_MODULE_DATA = 'EDIT_MODULE_DATA' 12 | export const RESET_RENDER_STATE = 'RESET_RENDER_STATE' 13 | -------------------------------------------------------------------------------- /src/utils/index.js: -------------------------------------------------------------------------------- 1 | var styleKey = { 2 | "backgroundImage": "url(%s)" 3 | } 4 | var styleArr = ['padding','margin'] 5 | 6 | export function createStyles(data) { 7 | let styles = {} 8 | if(data.style) { 9 | for(let key in data.style.value){ 10 | let val = data.style.value[key].value 11 | if(!val) continue; 12 | if(key in styleKey) { 13 | val = styleKey[key].replace("%s", val) 14 | } 15 | if(styleArr.indexOf(key) !== -1) { 16 | val = val.split(" ").map(a=>`${a}px`).join(" ") 17 | } 18 | styles[key] = val 19 | } 20 | } 21 | return styles 22 | } 23 | 24 | /** 25 | * 26 | * @param {Element} element 27 | * @return {Object} {top, right, bottom, left} in pixels 28 | */ 29 | 30 | export function position (element) { 31 | var box = element.getBoundingClientRect() 32 | var scrollTop = window.scrollY 33 | var scrollLeft = window.scrollX 34 | // Has to be copied since ClientRects is immutable 35 | return { 36 | top: box.top + scrollTop, 37 | right: box.right + scrollLeft, 38 | left: box.left + scrollLeft, 39 | bottom: box.bottom + scrollTop, 40 | width: box.width, 41 | height: box.height 42 | } 43 | } 44 | 45 | /** 46 | * @param {Element} child the subject element 47 | * @param {Element} [parent] offset will be calculated relative to this element. 48 | * This parameter is optional and will default to the offsetparent of the 49 | * `child` element 50 | * @return {Object} {x, y} in pixels 51 | */ 52 | 53 | export function offset (child, parent) { 54 | // default to comparing with the offsetparent 55 | parent || (parent = offsetParent(child)) 56 | if (!parent) { 57 | parent = position(child) 58 | return { 59 | left: parent.left, 60 | top: parent.top 61 | } 62 | } 63 | 64 | var offset = position(child) 65 | var parentOffset = position(parent) 66 | var css = getComputedStyle(child) 67 | 68 | // Subtract element margins 69 | offset.top -= parseFloat(css.marginTop) || 0 70 | offset.left -= parseFloat(css.marginLeft) || 0 71 | 72 | // Allow for the offsetparent's border 73 | offset.top -= parent.clientTop 74 | offset.left -= parent.clientLeft 75 | 76 | return { 77 | left: offset.left - parentOffset.left, 78 | top: offset.top - parentOffset.top 79 | } 80 | } 81 | 82 | /** 83 | * 84 | * @param {Element} element 85 | * @return {Element} if a positioned parent exists 86 | */ 87 | 88 | function offsetParent (element) { 89 | var parent = element.offsetParent 90 | while (parent && getComputedStyle(parent).position === "static") { 91 | parent = parent.offsetParent 92 | } 93 | return parent 94 | } 95 | -------------------------------------------------------------------------------- /src/views/Changelog.vue: -------------------------------------------------------------------------------- 1 | 63 | 69 | 130 | -------------------------------------------------------------------------------- /src/views/Designer.vue: -------------------------------------------------------------------------------- 1 | 35 | 36 | 232 | 233 | 234 | 326 | -------------------------------------------------------------------------------- /src/views/Home.vue: -------------------------------------------------------------------------------- 1 | 40 | 71 | 107 | -------------------------------------------------------------------------------- /src/views/Layout.vue: -------------------------------------------------------------------------------- 1 | 9 | 34 | 42 | -------------------------------------------------------------------------------- /src/views/Login.vue: -------------------------------------------------------------------------------- 1 | 13 | 29 | 46 | -------------------------------------------------------------------------------- /src/views/PageList.vue: -------------------------------------------------------------------------------- 1 | 67 | 154 | 225 | -------------------------------------------------------------------------------- /src/views/Preview.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 23 | 24 | 44 | -------------------------------------------------------------------------------- /src/views/Users.vue: -------------------------------------------------------------------------------- 1 | 34 | 67 | 91 | -------------------------------------------------------------------------------- /static/.gitKeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fireyy/piper/55f254709184991d26d37327e6408a9cedfc7654/static/.gitKeep --------------------------------------------------------------------------------