diff --git a/gulpfile.js b/gulpfile.js index 1ee6470f1..2ac9305e8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,43 +1,45 @@ const gulp = require('gulp'); -// gulp 核心方法 +// gulp core function const { src, dest, series, parallel, watch } = require('gulp'); -// gulp压缩js +// gulp compress js const uglify = require('gulp-uglify'); -// gulp判断 +// gulp judgment const gulpif = require('gulp-if'); -// gulp压缩css +// gulp compress css const cleanCSS = require('gulp-clean-css'); -// 删除文件 +// Delete Files const del = require('delete'); -// 实时刷新浏览器 +// Refresh the browser in real time const browserSync = require('browser-sync').create(); const reload = browserSync.reload; -// 文件合并 -const useref = require('gulp-useref'); - -// rollup打包,处理es6模块 +// According to html reference, files are merged +// const useref = require('gulp-useref'); +// File merge +const concat = require('gulp-concat'); +// rollup packaging, processing es6 modules const { rollup } = require('rollup'); -// rollup寻找node_modules模块 +// rollup looks for node_modules module const { nodeResolve } = require('@rollup/plugin-node-resolve'); -// rollup把commonjs模块转化为es6模块 +// rollup converts commonjs module to es6 module const commonjs = require('@rollup/plugin-commonjs'); -// rollup代码压缩 +// rollup code compression const terser = require('rollup-plugin-terser').terser; // rollup babel plugin, support the latest ES grammar const babel = require('@rollup/plugin-babel').default; -// 区分开发与生产环境 -const production = !process.env.ROLLUP_WATCH; +// Distinguish development and production environments +const production = process.env.NODE_ENV === 'production' ? true : false; -// uglify js压缩配置 https://github.com/mishoo/UglifyJS#minify-options +// uglify js Compression configuration https://github.com/mishoo/UglifyJS#minify-options const uglifyOptions = { compress: { drop_console: true } } +// babel config const babelConfig = { babelHelpers: 'bundled', - exclude: 'node_modules/**', // 只编译我们的源代码 + exclude: 'node_modules/**', // Only compile our source code plugins: [ ], presets: [ @@ -45,37 +47,108 @@ const babelConfig = { ] }; +// file handler paths +const paths = { + // static resources,contains index.html, fonts and images,and extension plugins dependency + staticHtml: ['src/*.html'], + staticFonts: ['src/fonts/**'], + staticImages: ['src/plugins/images/*.png'], + staticExpendPlugins: ['src/expendPlugins/**', '!src/expendPlugins/**/plugin.js'], + staticDemoData: ['src/demoData/*.js'], + staticCssImages: ['src/css/**','!src/css/*.css'], + + // static resources dest + destStaticHtml: ['dist'], + destStaticFonts: ['dist/fonts'], + destStaticImages: ['dist/plugins/images'], + destStaticExpendPlugins: ['dist/expendPlugins'], + destStaticDemoData: ['dist/demoData'], + destStaticCssImages: ['dist/css'], + + //core es module + core: ['src/**/*.js','!src/demoData/*.js','src/expendPlugins/**/plugin.js','!src/plugins/js/*.js'], + + //plugins src + pluginsCss: ['src/plugins/css/*.css'], + plugins: ['src/plugins/*.css'], + css:['src/css/*.css'], + pluginsJs:[ + 'src/plugins/js/jquery.min.js', + 'src/plugins/js/clipboard.min.js', + 'src/plugins/js/spectrum.min.js', + 'src/plugins/js/jquery-ui.min.js', + 'src/plugins/js/jquery.mousewheel.min.js', + 'src/plugins/js/moment.min.js', + 'src/plugins/js/moment-timezone-with-data.min.js', + 'src/plugins/js/moment-msdate.js', + 'src/plugins/js/numeral.min.js', + 'src/plugins/js/html2canvas.min.js', + 'src/plugins/js/pako.min.js', + 'src/plugins/js/localforage.min.js', + 'src/plugins/js/lodash.min.js', + 'src/plugins/js/daterangepicker.js', + 'src/plugins/js/jstat.min.js' + ], + + //plugins concat + concatPluginsCss: 'pluginsCss.css', + concatPlugins: 'plugins.css', + concatCss: 'luckysheet.css', + concatPluginsJs: 'plugin.js', + + //plugins dest + destPluginsCss: ['dist/plugins/css'], + destPlugins: ['dist/plugins'], + destCss: ['dist/css'], + destPluginsJs: ['dist/plugins/js'], + + // Package directory + dist: 'dist', +}; -// 清除dist目录 +// Clear the dist directory function clean() { - return del(['dist']); + return del([paths.dist]); } -//监听文件+重载 -function watchReload() { - core(); - serve(); - const watcher = watch(['src/**']); +// Static server +function serve(done) { + browserSync.init({ + server: { + baseDir: paths.dist + } + }, done) +} - // 多次刷新节流 - let reloadTimer = null; - watcher.on('change', function (path, stats) { - +// Monitoring file changes +function watcher(done) { + watch(paths.core,{ delay: 500 }, series(core, reloadBrowser)); + + // watch plugins and css + watch(paths.pluginsCss,{ delay: 500 }, series(pluginsCss, reloadBrowser)); + watch(paths.plugins,{ delay: 500 }, series(plugins, reloadBrowser)); + watch(paths.css,{ delay: 500 }, series(css, reloadBrowser)); + watch(paths.pluginsJs,{ delay: 500 }, series(pluginsJs, reloadBrowser)); + + // watch static + watch(paths.staticHtml,{ delay: 500 }, series(copyStaticHtml, reloadBrowser)); + watch(paths.staticFonts,{ delay: 500 }, series(copyStaticFonts, reloadBrowser)); + watch(paths.staticImages,{ delay: 500 }, series(copyStaticImages, reloadBrowser)); + watch(paths.staticExpendPlugins,{ delay: 500 }, series(copyStaticExpendPlugins, reloadBrowser)); + watch(paths.staticDemoData,{ delay: 500 }, series(copyStaticDemoData, reloadBrowser)); + watch(paths.staticCssImages,{ delay: 500 }, series(copyStaticCssImages, reloadBrowser)); + + done(); +} - if (reloadTimer !== null) { - clearTimeout(reloadTimer); - return; - } - reloadTimer = setTimeout(() => { - reload(); - core(); - reloadTimer = null; - }, 500); +// Refresh browser +function reloadBrowser(done) { + reload(); - }); + done(); } -//打包核心代码 +//Package the core code async function core() { const bundle = await rollup({ input: 'src/index.js', @@ -87,57 +160,88 @@ async function core() { // extract: true, // // minimize: isProductionEnv, // }), - // production && terser(), // minify, but only in production + production && terser(), // minify, but only in production babel(babelConfig) ], }); - return bundle.write({ - file: 'dist/luckysheet.js', + bundle.write({ + file: 'dist/luckysheet.umd.js', format: 'umd', name: 'luckysheet', sourcemap: true }); + + if(production){ + bundle.write({ + file: 'dist/luckysheet.esm.js', + format: 'esm', + name: 'luckysheet', + sourcemap: true + }); + } + } -// 打包js -function js() { - return src(['src/**/*.html', '!src/luckysheet-core.js','!src/luckysheet-function.js','!src/luckysheet-chart.js']) - .pipe(useref(), function () { - return vinylPaths(del) - }) - .pipe(gulpif(isJavaScript, uglify(uglifyOptions))) - .pipe(gulpif(isCss, cleanCSS())) - .pipe(dest('dist/')) +// According to the build tag in html, package js and css +function pluginsCss() { + return src(paths.pluginsCss) + .pipe(concat(paths.concatPluginsCss)) + .pipe(gulpif(production, cleanCSS())) + .pipe(dest(paths.destPluginsCss)) + } -// 打包其他文件 -function otherFile() { - return src(['src/**', '!src/**/*.html', '!src/**/*.js', '!src/**/*.css', '!src/luckysheet-core.js','!src/luckysheet-function.js','!src/luckysheet-chart.js']) - .pipe(dest('dist/')) + +function plugins() { + return src(paths.plugins) + .pipe(concat(paths.concatPlugins)) + .pipe(gulpif(production, cleanCSS())) + .pipe(dest(paths.destPlugins)); } -// 静态服务器 -function serve() { - browserSync.init({ - server: { - baseDir: "./" - } - }); +function css() { + return src(paths.css) + .pipe(concat(paths.concatCss)) + .pipe(gulpif(production, cleanCSS())) + .pipe(dest(paths.destCss)); } -// 判断文件的扩展名是否是 '.js' , 且需要为未压缩过的js -function isJavaScript(file) { - return file.extname === '.js'; +function pluginsJs() { + return src(paths.pluginsJs) + .pipe(concat(paths.concatPluginsJs)) + .pipe(gulpif(production, uglify(uglifyOptions))) + .pipe(dest(paths.destPluginsJs)); } -// 判断文件的扩展名是否是 '.css' , 且需要为未压缩过的css -function isCss(file) { - return file.extname === '.css'; +// Copy static resources +function copyStaticHtml(){ + return src(paths.staticHtml) + .pipe(dest(paths.destStaticHtml)); +} +function copyStaticFonts(){ + return src(paths.staticFonts) + .pipe(dest(paths.destStaticFonts)); +} +function copyStaticImages(){ + return src(paths.staticImages) + .pipe(dest(paths.destStaticImages)); +} +function copyStaticExpendPlugins(){ + return src(paths.staticExpendPlugins) + .pipe(dest(paths.destStaticExpendPlugins)); +} +function copyStaticDemoData(){ + return src(paths.staticDemoData) + .pipe(dest(paths.destStaticDemoData)); +} +function copyStaticCssImages(){ + return src(paths.staticCssImages) + .pipe(dest(paths.destStaticCssImages)); } -const build = series(clean, parallel(js, otherFile, core)); -const dev = watchReload; +const dev = series(clean, parallel(pluginsCss, plugins, css, pluginsJs, copyStaticHtml, copyStaticFonts, copyStaticImages, copyStaticExpendPlugins, copyStaticDemoData, copyStaticCssImages, core), watcher, serve); +const build = series(clean, parallel(pluginsCss, plugins, css, pluginsJs, copyStaticHtml, copyStaticFonts, copyStaticImages, copyStaticExpendPlugins, copyStaticDemoData, copyStaticCssImages, core)); -exports.build = build; exports.dev = dev; -exports.default = build; \ No newline at end of file +exports.build = build; +exports.default = dev; \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index 8e9a128a0..000000000 --- a/index.html +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - Luckysheet - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - \ No newline at end of file diff --git a/package.json b/package.json index 8321facc8..2c184206d 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,11 @@ "@rollup/plugin-node-resolve": "^8.0.1", "browser-sync": "^2.26.7", "commitizen": "^4.1.2", + "cross-env": "^7.0.2", "delete": "^1.1.0", "gulp": "^4.0.2", "gulp-clean-css": "^4.3.0", + "gulp-concat": "^2.6.1", "gulp-if": "^3.0.0", "gulp-uglify": "^3.0.2", "gulp-useref": "^4.0.1", @@ -26,8 +28,8 @@ }, "dependencies": {}, "scripts": { - "build": "gulp build", - "dev": "gulp dev", + "build": "cross-env NODE_ENV=production gulp build", + "dev": "cross-env NODE_ENV=development gulp dev", "docs:dev": "vuepress dev docs", "docs:build": "vuepress build docs", "commit": "git-cz", diff --git a/demoData/sheetCell.js b/src/demoData/sheetCell.js similarity index 100% rename from demoData/sheetCell.js rename to src/demoData/sheetCell.js diff --git a/demoData/sheetComment.js b/src/demoData/sheetComment.js similarity index 100% rename from demoData/sheetComment.js rename to src/demoData/sheetComment.js diff --git a/demoData/sheetConditionFormat.js b/src/demoData/sheetConditionFormat.js similarity index 100% rename from demoData/sheetConditionFormat.js rename to src/demoData/sheetConditionFormat.js diff --git a/demoData/sheetFormula.js b/src/demoData/sheetFormula.js similarity index 100% rename from demoData/sheetFormula.js rename to src/demoData/sheetFormula.js diff --git a/demoData/sheetPivotTable.js b/src/demoData/sheetPivotTable.js similarity index 100% rename from demoData/sheetPivotTable.js rename to src/demoData/sheetPivotTable.js diff --git a/demoData/sheetPivotTableData.js b/src/demoData/sheetPivotTableData.js similarity index 100% rename from demoData/sheetPivotTableData.js rename to src/demoData/sheetPivotTableData.js diff --git a/demoData/sheetTable.js b/src/demoData/sheetTable.js similarity index 100% rename from demoData/sheetTable.js rename to src/demoData/sheetTable.js diff --git a/src/expendPlugins/chart/plugin.js b/src/expendPlugins/chart/plugin.js index 2bdba7599..5074356b7 100644 --- a/src/expendPlugins/chart/plugin.js +++ b/src/expendPlugins/chart/plugin.js @@ -5,12 +5,12 @@ const dependScripts = [ 'https://cdn.jsdelivr.net/npm/vue@2.6.11', 'https://unpkg.com/vuex@3.4.0', 'https://unpkg.com/element-ui/lib/index.js', - './src/expendPlugins/chart/chartmix.umd.js' + 'expendPlugins/chart/chartmix.umd.js' ] const dependLinks = [ 'https://unpkg.com/element-ui/lib/theme-chalk/index.css', - './src/expendPlugins/chart/chartmix.css' + 'expendPlugins/chart/chartmix.css' ] // Initialize the chart component diff --git a/src/index.html b/src/index.html new file mode 100644 index 000000000..dfa074d23 --- /dev/null +++ b/src/index.html @@ -0,0 +1,43 @@ + + + + + + + + + Luckysheet + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/src/luckysheet-chart.js b/src/luckysheet-chart.js deleted file mode 100644 index 720cbdf79..000000000 --- a/src/luckysheet-chart.js +++ /dev/null @@ -1,1105 +0,0 @@ -import luckysheet from './luckysheet-function' -// 防止chart部分报错,从luckysheet-chartMix.js中迁移出luckysheet部分作为核心主体,关于设置界面的部分放到chartMix vue工程 -// chart用到的各个变量 -luckysheet.chartparam = { - luckysheet_chart_point_config: null, - luckysheetCurrentChartMove: false, - luckysheetCurrentChartMoveTimeout: null, - luckysheetCurrentChartResize: null, - luckysheet_chart_rangefocus_timeout: null, - luckysheet_chart_rangefocus: false, - luckysheet_chart_data_select_state: false, - luckysheetCurrentChartMoveObj: null, - luckysheetCurrentChartMoveXy: [], - luckysheetCurrentChartMoveWinH: null, - luckysheetCurrentChartMoveWinW: null, - luckysheetInsertChartTosheetChange: true, - jgridCurrentChartSelection: null, - luckysheetCurrentChartResizeObj: null, - luckysheetCurrentChartResizeXy: null, - luckysheetCurrentChartResizeWinH: null, - luckysheetCurrentChartResizeWinW: null, - luckysheet_chartIns_index: -1, - luckysheetCurrentChartActive: false, - - jgridCurrentChartData: null, - luckysheetcurrentChart: null, - - luckysheet_chart_redo_click: false, - jgridCurrentChartType: null, - luckysheetCurrentChartStyle: null, - luckysheetCurrentChartCurrentType: null, - - luckysheetPreviousChart: '' //最近最新的图表json -} - -// 初始化图表 -luckysheet.chartInitial = function () { - $('#luckysheetdatavisual').click(function () { - - // 未加入chartMix插件时返回 - if(!window.generateChart){ - luckysheet.tooltip.info('提示', "图表插件暂未加入"); - return; - } - //防止watch生效 - // generator.isFirstEditor = true; - generator.ini(chartMixConfig) - - setTimeout(function () { - generator.showChartSettingComponent('notRefresh') //此处不刷新,插入完图表再刷新 - }, 0) - if (store.state.chartSetting.isqk) { - setTimeout(function () { - luckysheet.luckysheetsizeauto() - }, 0) - } - - // var chartAllType = 'highcharts|line|default' - var chartAllType = 'echarts|line|default' - - //如果只选中一个单元格,则自动填充选取 - var luckysheet_select_save = luckysheet.getluckysheet_select_save() - if ( - luckysheet_select_save.length == 1 && - luckysheet_select_save[0].row[0] == luckysheet_select_save[0].row[1] && - luckysheet_select_save[0].column[0] == luckysheet_select_save[0].column[1] - ) { - luckysheet.luckysheetMoveHighlightRange2('right', 'rangeOfSelect') - - luckysheet.luckysheetMoveHighlightRange2('down', 'rangeOfSelect') - - luckysheet_select_save = luckysheet.getluckysheet_select_save() - } - //处理右边的空白单元格,自动略过并修改选区 ---------------start - var shiftpositon_row = -1 - - var row_ed = - luckysheet_select_save[0]['row'][1] - luckysheet_select_save[0]['row'][0] - for ( - var r = luckysheet_select_save[0]['row'][0]; - r <= luckysheet_select_save[0]['row'][1]; - r++ - ) { - for ( - var c = luckysheet_select_save[0]['column'][0]; - c <= luckysheet_select_save[0]['column'][1]; - c++ - ) { - var value = luckysheet.getcellvalue(r, c, luckysheet.flowdata) - //console.log("value,r,c",value,r,c); - if (value != null && value.toString().length > 0) { - shiftpositon_row = r - break - } - } - - if (shiftpositon_row !== -1) { - break - } - } - - if (shiftpositon_row == -1) { - shiftpositon_row = 0 - } - - luckysheet_select_save[0]['row'] = [shiftpositon_row, shiftpositon_row] - luckysheet.setluckysheet_select_save(luckysheet_select_save) - - luckysheet.luckysheet_shiftpositon = $.extend(true, {}, luckysheet_select_save[0]) - luckysheet.luckysheetMoveEndCell('down', 'range', false, row_ed) - luckysheet_select_save = luckysheet.getluckysheet_select_save() - - var shiftpositon_col = -1 - var column_ed = - luckysheet_select_save[0]['column'][1] - luckysheet_select_save[0]['column'][0] - for ( - var c = luckysheet_select_save[0]['column'][0]; - c <= luckysheet_select_save[0]['column'][1]; - c++ - ) { - for ( - var r = luckysheet_select_save[0]['row'][0]; - r <= luckysheet_select_save[0]['row'][1]; - r++ - ) { - var value = luckysheet.getcellvalue(r, c, luckysheet.flowdata) - if (value != null && value.toString().length > 0) { - shiftpositon_col = c - break - } - } - - if (shiftpositon_col !== -1) { - break - } - } - - if (shiftpositon_col == -1) { - shiftpositon_col = 0 - } - - luckysheet_select_save[0]['column'] = [shiftpositon_col, shiftpositon_col] - luckysheet.setluckysheet_select_save(luckysheet_select_save) - - luckysheet.luckysheet_shiftpositon = $.extend(true, {}, luckysheet_select_save[0]) - luckysheet.luckysheetMoveEndCell('right', 'range', false, column_ed) - luckysheet_select_save = luckysheet.getluckysheet_select_save() - - var dataSheetIndex = luckysheet.currentSheetIndex //当前sheet的原始索引 - var rangeArray = $.extend(true, [], luckysheet_select_save) - - //处理右边的空白单元格,自动略过并修改选区 ---------------end - - //根据选区来获取数据,########需要支持多选区取得的数据################## - var chartData = luckysheet.getdatabyselection( - luckysheet_select_save[0], - dataSheetIndex - ) - // 获取原始数据 - generator.chartData = chartData - var rangeTxt = luckysheet.sheetmanage.getRangetxt( - dataSheetIndex, - rangeArray[0], - dataSheetIndex - ) - - var chartTheme = 'default' - - var winw = $(window).width(), - winh = $(window).height() - var $cellmain = $('#luckysheet-cell-main') - var scrollLeft = $cellmain.scrollLeft(), - scrollTop = $cellmain.scrollTop() - var myw = winw * 0.3, - myh = winw * 0.3 * 0.618 - var myLeft = (winw - myw) / 3 + scrollLeft + Math.round(Math.random() * 10), - myTop = (winh - myh) / 4 + scrollTop + Math.round(Math.random() * 10) //先计算好位置 - - console.dir(JSON.stringify(chartData)) - console.dir(JSON.stringify(rangeArray)) - //luckysheet.insertChartTosheet放到insertNewChart中 - generator.insertNewChart( - chartAllType, - chartData, - dataSheetIndex, - rangeArray, - rangeTxt, - chartTheme, - luckysheet.currentSheetIndex, - myh, - myw, - myLeft, - myTop - ) - // setTimeout(function(){//暂时使用setTimeout解决watch第一次触发监听的问题 - // generator.isFirstEditor = false; - // },1000); - }) -} - -// 图表数据区域拖动修改 -luckysheet.chart_selection = { - create: function (chart_id) { - var chart_json = store.state.chartSetting.chartList[chart_id] - - if (chart_json.rangeArray.length > 1) { - return - } - - $('#luckysheet-chart-rangeShow').empty() - $('#luckysheet-cell-selected-boxs').hide() - $('#luckysheet-cell-selected-focus').hide() - $('#luckysheet-rows-h-selected').hide() - $('#luckysheet-cols-h-selected').hide() - $('#luckysheet-row-count-show').hide() - $('#luckysheet-column-count-show').hide() - - var st_r = chart_json.rangeArray[0].row[0] - var st_c = chart_json.rangeArray[0].column[0] - - var rangeSplitArray = chart_json.rangeSplitArray - - //首行是否标题 - var rangeRowCheck = chart_json.rangeRowCheck - - if (rangeRowCheck.exits) { - var chart_rowtitle_html = getRangeShowHtml( - 'rowtitle', - rangeSplitArray.rowtitle.row[0] + st_r, - rangeSplitArray.rowtitle.row[1] + st_r, - rangeSplitArray.rowtitle.column[0] + st_c, - rangeSplitArray.rowtitle.column[1] + st_c - ) - } else { - var chart_rowtitle_html = '' - } - - //首列是否标题 - var rangeColCheck = chart_json.rangeColCheck - - if (rangeColCheck.exits) { - var chart_coltitle_html = getRangeShowHtml( - 'coltitle', - rangeSplitArray.coltitle.row[0] + st_r, - rangeSplitArray.coltitle.row[1] + st_r, - rangeSplitArray.coltitle.column[0] + st_c, - rangeSplitArray.coltitle.column[1] + st_c - ) - } else { - var chart_coltitle_html = '' - } - - //内容块 - var chart_content_html = getRangeShowHtml( - 'content', - rangeSplitArray.content.row[0] + st_r, - rangeSplitArray.content.row[1] + st_r, - rangeSplitArray.content.column[0] + st_c, - rangeSplitArray.content.column[1] + st_c - ) - - $('#luckysheet-chart-rangeShow').append( - chart_rowtitle_html + chart_coltitle_html + chart_content_html - ) - - function getRangeShowHtml(type, r1, r2, c1, c2) { - var visibledatarow = luckysheet.getvisibledatarow() - var visibledatacolumn = luckysheet.getvisibledatacolumn() - - var row = visibledatarow[r2], - row_pre = r1 - 1 == -1 ? 0 : visibledatarow[r1 - 1] - var col = visibledatacolumn[c2], - col_pre = c1 - 1 == -1 ? 0 : visibledatacolumn[c1 - 1] - - if (type == 'rowtitle') { - var color = '#C65151' - } - - if (type == 'coltitle') { - var color = '#9667C0' - } - - if (type == 'content') { - var color = '#4970D1' - } - - var html = - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
' - - return html - } - }, - rangeMove: false, - rangeMovexy: null, - rangeMoveIndex: null, - rangeMoveObj: null, - rangeMoveDraging: function (event, sheetBarHeight, statisticBarHeight) { - var chart_json = $.extend( - true, - {}, - store.state.chartSetting.chartList[store.state.chartSetting.chartCurrent] - ) - var st_r = chart_json.rangeArray[0].row[0] - var st_c = chart_json.rangeArray[0].column[0] - var rangeRowCheck = chart_json.rangeRowCheck - var rangeColCheck = chart_json.rangeColCheck - var rangeSplitArray = chart_json.rangeSplitArray - - var mouse = luckysheet.mouseposition(event.pageX, event.pageY) - var scrollLeft = $('#luckysheet-cell-main').scrollLeft() - var scrollTop = $('#luckysheet-cell-main').scrollTop() - - var x = mouse[0] + scrollLeft - var y = mouse[1] + scrollTop - - var winH = - $(window).height() + scrollTop - sheetBarHeight - statisticBarHeight, - winW = $(window).width() + scrollLeft - - var rowLocation = luckysheet.rowLocation(y), - row_index = rowLocation[2] - var colLocation = luckysheet.colLocation(x), - col_index = colLocation[2] - - var visibledatarow = luckysheet.getvisibledatarow() - var visibledatacolumn = luckysheet.getvisibledatacolumn() - - var $id = luckysheet.chart_selection.rangeMoveObj.attr('id') - - if ($id == 'luckysheet-chart-rangeShow-content') { - //行 - var row_s = - luckysheet.chart_selection.rangeMoveIndex[0] - - luckysheet.chart_selection.rangeMovexy[0] + - row_index - - if (rangeRowCheck.exits) { - if (row_s < st_r + rangeRowCheck.range[1] + 1 || y < 0) { - row_s = st_r + rangeRowCheck.range[1] + 1 - } - } else { - if (row_s < 0 || y < 0) { - row_s = 0 - } - } - - var row_e = - rangeSplitArray.content.row[1] - rangeSplitArray.content.row[0] + row_s - - if (row_e >= visibledatarow.length - 1 || y > winH) { - row_s = - visibledatarow.length - - 1 - - rangeSplitArray.content.row[1] + - rangeSplitArray.content.row[0] - row_e = visibledatarow.length - 1 - } - - //列 - var col_s = - luckysheet.chart_selection.rangeMoveIndex[1] - - luckysheet.chart_selection.rangeMovexy[1] + - col_index - if (rangeColCheck.exits) { - if (col_s < st_c + rangeColCheck.range[1] + 1 || x < 0) { - col_s = st_c + rangeColCheck.range[1] + 1 - } - } else { - if (col_s < 0 || x < 0) { - col_s = 0 - } - } - - var col_e = - rangeSplitArray.content.column[1] - - rangeSplitArray.content.column[0] + - col_s - - if (col_e >= visibledatacolumn.length - 1 || x > winW) { - col_s = - visibledatacolumn.length - - 1 - - rangeSplitArray.content.column[1] + - rangeSplitArray.content.column[0] - col_e = visibledatacolumn.length - 1 - } - - //更新 - if (rangeRowCheck.exits && rangeColCheck.exits) { - chart_json.rangeArray = [{ row: [st_r, row_e], column: [st_c, col_e] }] - chart_json.rangeSplitArray.range = { - row: [st_r, row_e], - column: [st_c, col_e] - } - - chart_json.rangeSplitArray.content = { - row: [row_s - st_r, row_e - st_r], - column: [col_s - st_c, col_e - st_c] - } - - chart_json.rangeSplitArray.rowtitle = { - row: chart_json.rangeSplitArray.rowtitle.row, - column: [col_s - st_c, col_e - st_c] - } - - chart_json.rangeSplitArray.coltitle = { - row: [row_s - st_r, row_e - st_r], - column: chart_json.rangeSplitArray.coltitle.column - } - } else if (rangeRowCheck.exits) { - chart_json.rangeArray = [{ row: [st_r, row_e], column: [col_s, col_e] }] - chart_json.rangeSplitArray.range = { - row: [st_r, row_e], - column: [col_s, col_e] - } - - chart_json.rangeSplitArray.content = { - row: [row_s - st_r, row_e - st_r], - column: chart_json.rangeSplitArray.content.column - } - } else if (rangeColCheck.exits) { - chart_json.rangeArray = [{ row: [row_s, row_e], column: [st_c, col_e] }] - chart_json.rangeSplitArray.range = { - row: [row_s, row_e], - column: [st_c, col_e] - } - - chart_json.rangeSplitArray.content = { - row: chart_json.rangeSplitArray.content.row, - column: [col_s - st_c, col_e - st_c] - } - } else { - chart_json.rangeArray = [ - { row: [row_s, row_e], column: [col_s, col_e] } - ] - chart_json.rangeSplitArray.range = { - row: [row_s, row_e], - column: [col_s, col_e] - } - } - } else if ($id == 'luckysheet-chart-rangeShow-rowtitle') { - //列 - var col_s = - luckysheet.chart_selection.rangeMoveIndex[1] - - luckysheet.chart_selection.rangeMovexy[1] + - col_index - - if (rangeColCheck.exits) { - if (col_s < st_c + rangeColCheck.range[1] + 1 || x < 0) { - col_s = st_c + rangeColCheck.range[1] + 1 - } - } else { - if (col_s < 0 || x < 0) { - col_s = 0 - } - } - - var col_e = - rangeSplitArray.rowtitle.column[1] - - rangeSplitArray.rowtitle.column[0] + - col_s - - if (col_e >= visibledatacolumn.length - 1 || x > winW) { - col_s = - visibledatacolumn.length - - 1 - - rangeSplitArray.rowtitle.column[1] + - rangeSplitArray.rowtitle.column[0] - col_e = visibledatacolumn.length - 1 - } - - //更新 - if (rangeColCheck.exits) { - chart_json.rangeArray = [ - { row: chart_json.rangeArray[0].row, column: [st_c, col_e] } - ] - chart_json.rangeSplitArray.range = { - row: chart_json.rangeArray[0].row, - column: [st_c, col_e] - } - - chart_json.rangeSplitArray.rowtitle = { - row: chart_json.rangeSplitArray.rowtitle.row, - column: [col_s - st_c, col_e - st_c] - } - chart_json.rangeSplitArray.content = { - row: chart_json.rangeSplitArray.content.row, - column: [col_s - st_c, col_e - st_c] - } - } else { - chart_json.rangeArray = [ - { row: chart_json.rangeArray[0].row, column: [col_s, col_e] } - ] - chart_json.rangeSplitArray.range = { - row: chart_json.rangeArray[0].row, - column: [col_s, col_e] - } - } - } else if ($id == 'luckysheet-chart-rangeShow-coltitle') { - //行 - var row_s = - luckysheet.chart_selection.rangeMoveIndex[0] - - luckysheet.chart_selection.rangeMovexy[0] + - row_index - if (rangeRowCheck.exits) { - if (row_s < st_r + rangeRowCheck.range[1] + 1 || y < 0) { - row_s = st_r + rangeRowCheck.range[1] + 1 - } - } else { - if (row_s < 0 || y < 0) { - row_s = 0 - } - } - - //更新 - var row_e = - rangeSplitArray.coltitle.row[1] - - rangeSplitArray.coltitle.row[0] + - row_s - - if (row_e >= visibledatarow.length - 1 || y > winH) { - row_s = - visibledatarow.length - - 1 - - rangeSplitArray.coltitle.row[1] + - rangeSplitArray.coltitle.row[0] - row_e = visibledatarow.length - 1 - } - - if (rangeRowCheck.exits) { - chart_json.rangeArray = [ - { row: [st_r, row_e], column: chart_json.rangeArray[0].column } - ] - chart_json.rangeSplitArray.range = { - row: [st_r, row_e], - column: chart_json.rangeArray[0].column - } - - chart_json.rangeSplitArray.coltitle = { - row: [row_s - st_r, row_e - st_r], - column: chart_json.rangeSplitArray.coltitle.column - } - chart_json.rangeSplitArray.content = { - row: [row_s - st_r, row_e - st_r], - column: chart_json.rangeSplitArray.content.column - } - } else { - chart_json.rangeArray = [ - { row: [row_s, row_e], column: chart_json.rangeArray[0].column } - ] - chart_json.rangeSplitArray.range = { - row: [row_s, row_e], - column: chart_json.rangeArray[0].column - } - } - } - - //部分更新 - store.commit({ - type: 'updateChartItem', - key: 'rangeArray', - value: chart_json.rangeArray, - chartId: chart_json.chart_id - }) - store.commit({ - type: 'updateChartItem', - key: 'rangeSplitArray', - value: chart_json.rangeSplitArray, - chartId: chart_json.chart_id - }) - luckysheet.chart_selection.create(store.state.chartSetting.chartCurrent) - }, - rangeMoveDragged: function () { - luckysheet.chart_selection.rangeMove = false - - var chart_json = $.extend( - true, - {}, - store.state.chartSetting.chartList[store.state.chartSetting.chartCurrent] - ) - - var updateJson = {} - updateJson.chart_id = store.state.chartSetting.chartCurrent - updateJson.rangeTxt = luckysheet.sheetmanage.getRangetxt( - luckysheet.currentSheetIndex, - chart_json.rangeArray[0], - luckysheet.currentSheetIndex - ) - updateJson.chartData = luckysheet.getdatabyselection( - chart_json.rangeArray[0], - luckysheet.currentSheetIndex - ) - - var $id = luckysheet.chart_selection.rangeMoveObj.attr('id') - if ( - $id == 'luckysheet-chart-rangeShow-content' && - !chart_json.rangeRowCheck.exits && - !chart_json.rangeColCheck.exits - ) { - //rangeMoveDraging中未更新chartData,在此使用新的chartData更新到updateJson - updateJson.rangeSplitArray = generator.getRangeSplitArray( - updateJson.chartData, - chart_json.rangeArray, - chart_json.rangeColCheck, - chart_json.rangeRowCheck - ) - } else { - updateJson.rangeSplitArray = chart_json.rangeSplitArray - } - - var chartAllTypeArray = chart_json.chartAllType.split('|') - var chartPro = chartAllTypeArray[0], - chartType = chartAllTypeArray[1], - chartStyle = chartAllTypeArray[2] - - updateJson.chartDataCache = generator.getChartDataCache( - updateJson.chartData, - updateJson.rangeSplitArray, - chartPro, - chartType, - chartStyle - ) - updateJson.chartDataSeriesOrder = generator.getChartDataSeriesOrder( - updateJson.chartDataCache.series[0].length - ) - // 是否是移动改变图形 - generator.drag = true - // 不增加点/线/区域 - generator.addPoint = false - generator.addLine = false - generator.addArea = false - if (chartType == 'funnel' || chartType == 'gauge') { - updateJson.defaultOption = generator.addDataToOption1( - chart_json.defaultOption, - updateJson.chartDataCache, - updateJson.chartDataSeriesOrder, - chartPro, - chartType, - chartStyle - ) - } else { - updateJson.defaultOption = generator.addDataToOption( - chart_json.defaultOption, - updateJson.chartDataCache, - updateJson.chartDataSeriesOrder, - chartPro, - chartType, - chartStyle - ) - } - - // console.dir(JSON.stringify(updateJson.defaultOption)) - generator.patchVueSet(updateJson) - generator.generateChart( - updateJson.defaultOption, - chart_json.chartTheme, - chart_json.chartAllType, - $('#' + updateJson.chart_id).get(0) - ) - }, - rangeResize: false, - rangeResizexy: null, - rangeResizeIndex: null, - rangeResizeObj: null, - rangeResizeDraging: function (event, sheetBarHeight, statisticBarHeight) { - var chart_json = $.extend( - true, - {}, - store.state.chartSetting.chartList[store.state.chartSetting.chartCurrent] - ) - var st_r = chart_json.rangeArray[0].row[0] - var st_c = chart_json.rangeArray[0].column[0] - var rangeRowCheck = chart_json.rangeRowCheck - var rangeColCheck = chart_json.rangeColCheck - var rangeSplitArray = chart_json.rangeSplitArray - - var mouse = luckysheet.mouseposition(event.pageX, event.pageY) - var scrollLeft = $('#luckysheet-cell-main').scrollLeft() - var scrollTop = $('#luckysheet-cell-main').scrollTop() - - var x = mouse[0] + scrollLeft - var y = mouse[1] + scrollTop - - var winH = - $(window).height() + scrollTop - sheetBarHeight - statisticBarHeight, - winW = $(window).width() + scrollLeft - - var rowLocation = luckysheet.rowLocation(y), - row_index = rowLocation[2] - var colLocation = luckysheet.colLocation(x), - col_index = colLocation[2] - - var visibledatarow = luckysheet.getvisibledatarow() - var visibledatacolumn = luckysheet.getvisibledatacolumn() - - var $id = luckysheet.chart_selection.rangeResizeObj.attr('id') - - if ($id == 'luckysheet-chart-rangeShow-content') { - var r1, r2, c1, c2 - - if (luckysheet.chart_selection.rangeResize == 'lt') { - r1 = luckysheet.chart_selection.rangeResizeIndex.row[0] - c1 = luckysheet.chart_selection.rangeResizeIndex.column[0] - - r2 = luckysheet.chart_selection.rangeResizeIndex.row[1] - c2 = luckysheet.chart_selection.rangeResizeIndex.column[1] - } else if (luckysheet.chart_selection.rangeResize == 'lb') { - r1 = luckysheet.chart_selection.rangeResizeIndex.row[1] - c1 = luckysheet.chart_selection.rangeResizeIndex.column[0] - - r2 = luckysheet.chart_selection.rangeResizeIndex.row[0] - c2 = luckysheet.chart_selection.rangeResizeIndex.column[1] - } else if (luckysheet.chart_selection.rangeResize == 'rt') { - r1 = luckysheet.chart_selection.rangeResizeIndex.row[0] - c1 = luckysheet.chart_selection.rangeResizeIndex.column[1] - - r2 = luckysheet.chart_selection.rangeResizeIndex.row[1] - c2 = luckysheet.chart_selection.rangeResizeIndex.column[0] - } else if (luckysheet.chart_selection.rangeResize == 'rb') { - r1 = luckysheet.chart_selection.rangeResizeIndex.row[1] - c1 = luckysheet.chart_selection.rangeResizeIndex.column[1] - - r2 = luckysheet.chart_selection.rangeResizeIndex.row[0] - c2 = luckysheet.chart_selection.rangeResizeIndex.column[0] - } - - //行 - if (rangeRowCheck.exits) { - var row_s = r1 - luckysheet.chart_selection.rangeResizexy[0] + row_index - - if (row_s < st_r + rangeRowCheck.range[1] + 1 || y < 0) { - row_s = st_r + rangeRowCheck.range[1] + 1 - } else if (row_s >= visibledatarow.length - 1 || y > winH) { - row_s = visibledatarow.length - 1 - } - } else { - var row_s = st_r - luckysheet.chart_selection.rangeResizexy[0] + row_index - - if (row_s < 0 || y < 0) { - row_s = 0 - } else if (row_s >= visibledatarow.length - 1 || y > winH) { - row_s = visibledatarow.length - 1 - } - } - - //列 - if (rangeColCheck.exits) { - var col_s = c1 - luckysheet.chart_selection.rangeResizexy[1] + col_index - - if (col_s < st_c + rangeColCheck.range[1] + 1 || x < 0) { - col_s = st_c + rangeColCheck.range[1] + 1 - } else if (col_s >= visibledatacolumn.length - 1 || x > winW) { - col_s = visibledatacolumn.length - 1 - } - } else { - var col_s = st_c - luckysheet.chart_selection.rangeResizexy[1] + col_index - - if (col_s < 0 || x < 0) { - col_s = 0 - } else if (col_s >= visibledatacolumn.length - 1 || x > winW) { - col_s = visibledatacolumn.length - 1 - } - } - - var obj_r1, obj_r2, obj_c1, obj_c2 - - if (row_s > r2) { - obj_r1 = r2 - obj_r2 = row_s - } else { - obj_r1 = row_s - obj_r2 = r2 - } - - if (col_s > c2) { - obj_c1 = c2 - obj_c2 = col_s - } else { - obj_c1 = col_s - obj_c2 = c2 - } - - if (!rangeRowCheck.exits && !rangeColCheck.exits) { - chart_json.rangeArray = [ - { row: [obj_r1, obj_r2], column: [obj_c1, obj_c2] } - ] - chart_json.rangeSplitArray.range = { - row: [obj_r1, obj_r2], - column: [obj_c1, obj_c2] - } - } else { - chart_json.rangeArray = [ - { row: [st_r, obj_r2], column: [st_c, obj_c2] } - ] - chart_json.rangeSplitArray.range = { - row: [st_r, obj_r2], - column: [st_c, obj_c2] - } - - chart_json.rangeSplitArray.content = { - row: [obj_r1 - st_r, obj_r2 - st_r], - column: [obj_c1 - st_c, obj_c2 - st_c] - } - - if (rangeRowCheck.exits) { - chart_json.rangeSplitArray.rowtitle = { - row: chart_json.rangeSplitArray.rowtitle.row, - column: [obj_c1 - st_c, obj_c2 - st_c] - } - } - - if (rangeColCheck.exits) { - chart_json.rangeSplitArray.coltitle = { - row: [obj_r1 - st_r, obj_r2 - st_r], - column: chart_json.rangeSplitArray.coltitle.column - } - } - } - } else if ($id == 'luckysheet-chart-rangeShow-rowtitle') { - var c1, c2 - - if ( - luckysheet.chart_selection.rangeResize == 'lt' || - luckysheet.chart_selection.rangeResize == 'lb' - ) { - c1 = luckysheet.chart_selection.rangeResizeIndex.column[0] - c2 = luckysheet.chart_selection.rangeResizeIndex.column[1] - } else if ( - luckysheet.chart_selection.rangeResize == 'rt' || - luckysheet.chart_selection.rangeResize == 'rb' - ) { - c1 = luckysheet.chart_selection.rangeResizeIndex.column[1] - c2 = luckysheet.chart_selection.rangeResizeIndex.column[0] - } - - //列 - if (rangeColCheck.exits) { - var col_s = c1 - luckysheet.chart_selection.rangeResizexy[1] + col_index - - if (col_s < st_c + rangeColCheck.range[1] + 1 || x < 0) { - col_s = st_c + rangeColCheck.range[1] + 1 - } else if (col_s >= visibledatacolumn.length - 1 || x > winW) { - col_s = visibledatacolumn.length - 1 - } - } else { - var col_s = st_c - luckysheet.chart_selection.rangeResizexy[1] + col_index - - if (col_s < 0 || x < 0) { - col_s = 0 - } else if (col_s >= visibledatacolumn.length - 1 || x > winW) { - col_s = visibledatacolumn.length - 1 - } - } - - var obj_c1, obj_c2 - - if (col_s > c2) { - obj_c1 = c2 - obj_c2 = col_s - } else { - obj_c1 = col_s - obj_c2 = c2 - } - - //更新 - if (!rangeColCheck.exits) { - chart_json.rangeArray = [ - { row: chart_json.rangeArray[0].row, column: [obj_c1, obj_c2] } - ] - chart_json.rangeSplitArray.range = { - row: chart_json.rangeArray[0].row, - column: [obj_c1, obj_c2] - } - } else { - chart_json.rangeArray = [ - { row: chart_json.rangeArray[0].row, column: [st_c, obj_c2] } - ] - chart_json.rangeSplitArray.range = { - row: chart_json.rangeArray[0].row, - column: [st_c, obj_c2] - } - - chart_json.rangeSplitArray.rowtitle = { - row: chart_json.rangeSplitArray.rowtitle.row, - column: [obj_c1 - st_c, obj_c2 - st_c] - } - chart_json.rangeSplitArray.content = { - row: chart_json.rangeSplitArray.content.row, - column: [obj_c1 - st_c, obj_c2 - st_c] - } - } - } else if ($id == 'luckysheet-chart-rangeShow-coltitle') { - var r1, r2 - - if ( - luckysheet.chart_selection.rangeResize == 'lt' || - luckysheet.chart_selection.rangeResize == 'rt' - ) { - r1 = luckysheet.chart_selection.rangeResizeIndex.row[0] - r2 = luckysheet.chart_selection.rangeResizeIndex.row[1] - } else if ( - luckysheet.chart_selection.rangeResize == 'lb' || - luckysheet.chart_selection.rangeResize == 'rb' - ) { - r1 = luckysheet.chart_selection.rangeResizeIndex.row[1] - r2 = luckysheet.chart_selection.rangeResizeIndex.row[0] - } - - //行 - if (rangeRowCheck.exits) { - var row_s = r1 - luckysheet.chart_selection.rangeResizexy[0] + row_index - - if (row_s < st_r + rangeRowCheck.range[1] + 1 || y < 0) { - row_s = st_r + rangeRowCheck.range[1] + 1 - } else if (row_s >= visibledatarow.length - 1 || y > winH) { - row_s = visibledatarow.length - 1 - } - } else { - var row_s = st_r - luckysheet.chart_selection.rangeResizexy[0] + row_index - - if (row_s < 0 || y < 0) { - row_s = 0 - } else if (row_s >= visibledatarow.length - 1 || y > winH) { - row_s = visibledatarow.length - 1 - } - } - - var obj_r1, obj_r2 - - if (row_s > r2) { - obj_r1 = r2 - obj_r2 = row_s - } else { - obj_r1 = row_s - obj_r2 = r2 - } - - //更新 - if (!rangeRowCheck.exits) { - chart_json.rangeArray = [ - { row: [obj_r1, obj_r2], column: chart_json.rangeArray[0].column } - ] - chart_json.rangeSplitArray.range = { - row: [obj_r1, obj_r2], - column: chart_json.rangeArray[0].column - } - } else { - chart_json.rangeArray = [ - { row: [st_r, obj_r2], column: chart_json.rangeArray[0].column } - ] - chart_json.rangeSplitArray.range = { - row: [st_r, obj_r2], - column: chart_json.rangeArray[0].column - } - - chart_json.rangeSplitArray.coltitle = { - row: [obj_r1 - st_r, obj_r2 - st_r], - column: chart_json.rangeSplitArray.coltitle.column - } - chart_json.rangeSplitArray.content = { - row: [obj_r1 - st_r, obj_r2 - st_r], - column: chart_json.rangeSplitArray.content.column - } - } - } - - //部分更新 - store.commit({ - type: 'updateChartItem', - key: 'rangeArray', - value: chart_json.rangeArray, - chartId: chart_json.chart_id - }) - store.commit({ - type: 'updateChartItem', - key: 'rangeSplitArray', - value: chart_json.rangeSplitArray, - chartId: chart_json.chart_id - }) - luckysheet.chart_selection.create(store.state.chartSetting.chartCurrent) - }, - rangeResizeDragged: function () { - luckysheet.chart_selection.rangeResize = null - - var chart_json = $.extend( - true, - {}, - store.state.chartSetting.chartList[store.state.chartSetting.chartCurrent] - ) - - var updateJson = {} - - updateJson.chart_id = store.state.chartSetting.chartCurrent - updateJson.rangeTxt = luckysheet.sheetmanage.getRangetxt( - luckysheet.currentSheetIndex, - chart_json.rangeArray[0], - luckysheet.currentSheetIndex - ) - updateJson.chartData = luckysheet.getdatabyselection( - chart_json.rangeArray[0], - luckysheet.currentSheetIndex - ) - - var $id = luckysheet.chart_selection.rangeResizeObj.attr('id') - if ( - $id == 'luckysheet-chart-rangeShow-content' && - !chart_json.rangeRowCheck.exits && - !chart_json.rangeColCheck.exits - ) { - //采用updateJson.chartData - updateJson.rangeSplitArray = generator.getRangeSplitArray( - updateJson.chartData, - chart_json.rangeArray, - chart_json.rangeColCheck, - chart_json.rangeRowCheck - ) - } else { - updateJson.rangeSplitArray = chart_json.rangeSplitArray - } - - var chartAllTypeArray = chart_json.chartAllType.split('|') - var chartPro = chartAllTypeArray[0], - chartType = chartAllTypeArray[1], - chartStyle = chartAllTypeArray[2] - - updateJson.chartDataCache = generator.getChartDataCache( - updateJson.chartData, - updateJson.rangeSplitArray, - chartPro, - chartType, - chartStyle - ) - updateJson.chartDataSeriesOrder = generator.getChartDataSeriesOrder( - updateJson.chartDataCache.series[0].length - ) - if (chartType == 'funnel' || chartType == 'gauge') { - updateJson.defaultOption = generator.addDataToOption1( - chart_json.defaultOption, - updateJson.chartDataCache, - updateJson.chartDataSeriesOrder, - chartPro, - chartType, - chartStyle - ) - } else { - updateJson.defaultOption = generator.addDataToOption( - chart_json.defaultOption, - updateJson.chartDataCache, - updateJson.chartDataSeriesOrder, - chartPro, - chartType, - chartStyle - ) - } - - generator.patchVueSet(updateJson) - - generator.generateChart( - updateJson.defaultOption, - chart_json.chartTheme, - chart_json.chartAllType, - $('#' + updateJson.chart_id).get(0) - ) - } -} - -export default luckysheet \ No newline at end of file