Skip to content

Commit e660288

Browse files
author
yanjun.zsj
committed
1、修复组件初始化后,组件位置发生变化,拉线位置错乱的问题
2、babel升级(6->7)
1 parent aedb088 commit e660288

File tree

5 files changed

+56
-45
lines changed

5 files changed

+56
-45
lines changed

.babelrc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
{
2-
"presets": ["react", "es2015", "stage-3"],
2+
"presets": ["@babel/preset-react", "@babel/preset-env"],
33
"plugins": [
4-
"transform-runtime"
4+
"@babel/plugin-transform-runtime",
5+
["@babel/plugin-proposal-class-properties", { "loose": true }],
6+
// Stage 1
7+
"@babel/plugin-proposal-export-default-from",
8+
"@babel/plugin-proposal-logical-assignment-operators",
9+
["@babel/plugin-proposal-optional-chaining", { "loose": false }],
10+
["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }],
11+
["@babel/plugin-proposal-nullish-coalescing-operator", { "loose": false }],
12+
"@babel/plugin-proposal-do-expressions"
513
]
614
}

package.json

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,39 @@
3131
"LICENSE"
3232
],
3333
"devDependencies": {
34-
"babel-eslint": "^10.0.1",
35-
"eslint": "^5.0.1",
36-
"eslint-loader": "^2.0.0",
37-
"eslint-plugin-react": "^7.10.0",
34+
"@babel/plugin-proposal-class-properties": "^7.7.0",
35+
"@babel/plugin-proposal-do-expressions": "^7.6.0",
36+
"@babel/plugin-proposal-export-default-from": "^7.5.2",
37+
"@babel/plugin-proposal-logical-assignment-operators": "^7.2.0",
38+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
39+
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
40+
"@babel/plugin-proposal-pipeline-operator": "^7.5.0",
41+
"babel-eslint": "^10.0.3",
42+
"eslint": "^6.4.0",
43+
"eslint-loader": "^3.0.0",
44+
"eslint-plugin-react": "^7.14.3",
3845
"jsinspect": "^0.12.7",
39-
"less": "^3.8.1",
40-
"webpack-dev-server": "^3.1.5"
46+
"less": "^3.10.3",
47+
"webpack-dev-server": "^3.8.1"
4148
},
4249
"dependencies": {
43-
"babel-core": "^6.26.3",
44-
"babel-loader": "^7.1.2",
45-
"babel-plugin-transform-runtime": "^6.23.0",
46-
"babel-preset-env": "^1.6.0",
47-
"babel-preset-es2015": "^6.24.1",
48-
"babel-preset-react": "^6.24.1",
49-
"babel-preset-stage-3": "^6.24.1",
50-
"cross-env": "^5.1.1",
51-
"css-loader": "^0.28.7",
52-
"less-loader": "^4.0.5",
50+
"@babel/core": "^7.6.0",
51+
"@babel/plugin-transform-runtime": "^7.6.0",
52+
"@babel/polyfill": "^7.6.0",
53+
"@babel/preset-env": "^7.6.0",
54+
"@babel/preset-react": "^7.0.0",
55+
"@babel/runtime": "^7.6.0",
56+
"babel-loader": "^8.0.6",
57+
"cross-env": "^6.0.0",
58+
"css-loader": "^3.2.0",
59+
"less-loader": "^5.0.0",
60+
"style-loader": "^1.0.0",
61+
"url-loader": "^2.1.0",
62+
"webpack": "^4.40.2",
63+
"webpack-cli": "^3.3.9",
5364
"lodash": "^4.17.11",
5465
"react": "^16.8.4",
5566
"react-dom": "^16.8.4",
56-
"sortablejs": "^1.7.0",
57-
"style-loader": "^0.19.0",
58-
"url-loader": "^0.6.2",
59-
"webpack": "^4.16.5",
60-
"webpack-cli": "^3.1.0"
67+
"sortablejs": "^1.7.0"
6168
}
6269
}

src/drawLines.jsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@ const defaultState = {
1616
};
1717

1818
class DrawLines extends Component {
19+
baseXY = {
20+
left: 0,
21+
top: 0
22+
}
1923
constructor(props) {
2024
super(props);
2125
this.state = {
22-
baseXY:{
23-
left: 0,
24-
top: 0
25-
},
2626
...defaultState
2727
};
2828
}
2929
componentDidMount() {
3030
const me = this;
31-
const baseXY = getOffset(this.drawEle);
31+
this.baseXY = getOffset(this.drawEle);
3232
const box = document.querySelector('.react-field-mapping-box');
3333
let scrollTop = 0;
3434
let scrollLeft = 0;
35-
this.setState({
36-
baseXY
37-
});
3835
document.documentElement.onmousedown = (event) => {
3936
const eventDom = event.target;
4037
const className = eventDom && eventDom.className;
4138
if (className && typeof className === "string" && className.indexOf("source-column-icon") > -1) {
4239
event.preventDefault();
40+
if(this.baseXY !== getOffset(this.drawEle)) {
41+
this.baseXY = getOffset(this.drawEle);
42+
}
4343
let scrollEle = box;
4444
document.body.classList.add("user-select-none");
4545
const sourceData = _.find(me.props.sourceData, (o) => {
@@ -66,8 +66,8 @@ class DrawLines extends Component {
6666
if (this.state.drawing) {
6767
me.props.onDrawing && me.props.onDrawing(me.state.sourceData, me.props.relation);
6868
me.setState({
69-
endX: event.pageX - baseXY.left + scrollLeft,
70-
endY: event.pageY - baseXY.top + scrollTop
69+
endX: event.pageX - this.baseXY.left + scrollLeft,
70+
endY: event.pageY - this.baseXY.top + scrollTop
7171
});
7272
}
7373
};
@@ -111,8 +111,8 @@ class DrawLines extends Component {
111111
}
112112
domOperate(eventDom) {
113113
return {
114-
left: getOffset(eventDom).left - this.state.baseXY.left + 3,
115-
top: getOffset(eventDom).top - this.state.baseXY.top + 6,
114+
left: getOffset(eventDom).left - this.baseXY.left + 3,
115+
top: getOffset(eventDom).top - this.baseXY.top + 6,
116116
key: eventDom.offsetParent.getAttribute('data-key')
117117
};
118118
}

src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: yanjun.zsj
33
* @Date: 2019-07-30 14:05:00
44
* @LastEditors: yanjun.zsj
5-
* @LastEditTime: 2019-11-21 17:50:18
5+
* @LastEditTime: 2019-11-22 19:00:58
66
*/
77
/* @author yanjun.zsj
88
* @date 2018.11

webpack.config.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const path = require("path");
66
const webpack = require("webpack");
77
const env = process.env.NODE_ENV;
88
const entry = {
9-
fieldmapping: './src/index.js'
9+
fieldmapping: ['@babel/polyfill', './src/index.js']
1010
};
1111
const plugins = [
1212
new webpack.HotModuleReplacementPlugin(),
@@ -40,7 +40,8 @@ module.exports = {
4040
resolve: {
4141
alias: {
4242
'@': path.resolve(__dirname, 'src')
43-
}
43+
},
44+
extensions: ['.jsx', '.less', '.css', '.wasm', '.mjs', '.js', '.json']
4445
},
4546
module: {
4647
rules: [{
@@ -49,7 +50,7 @@ module.exports = {
4950
include: [
5051
path.resolve(__dirname, 'src')
5152
],
52-
loader: 'babel-loader'
53+
loader: ['babel-loader', 'eslint-loader']
5354
}, {
5455
test: /\.(png|jpg|gif)$/,
5556
use: [
@@ -64,12 +65,7 @@ module.exports = {
6465
test: /\.(less|css)$/,
6566
exclude: /node_modules/,
6667
use: ['style-loader', 'css-loader', 'less-loader']
67-
}, {
68-
test: /\.(js|jsx)$/,
69-
exclude: /node_modules/,
70-
loader: 'eslint-loader'
71-
}
72-
]
68+
}]
7369
},
7470
plugins: plugins
7571
};

0 commit comments

Comments
 (0)