Skip to content

Commit 9d7c78c

Browse files
committed
add new rotate-bar
1 parent 269a072 commit 9d7c78c

File tree

17 files changed

+95
-19
lines changed

17 files changed

+95
-19
lines changed

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
site
2+
.eslintrc.json
3+
shots
4+
.babelrc
5+
webpack.config.js

dist/crop.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
</div>
1919
</div>
2020
<resize-bar v-if="resize" ref="resizeBar" @resize="resizeImage"></resize-bar>
21+
<rotate-bar v-if="isRotate" @rotate="rotateImage"></rotate-bar>
2122
</div>
2223
</div>
2324
</template>
@@ -130,7 +131,9 @@ import drag from './lib/drag';
130131
import resize from './lib/resize';
131132
import GIF_LOADING_SRC from './lib/loading-gif';
132133
import helper from './lib/helper';
134+
import canvasHelper from './lib/canvas-helper';
133135
import ResizeBar from './resize-bar.vue';
136+
import RotateBar from './rotate-bar.vue';
134137
// set cropbox size in image
135138
const CROPBOX_PERCENT = 75;
136139
const isMobile = helper.isMobile;
@@ -139,6 +142,7 @@ const areaHeight = window.innerHeight - 110;
139142
export default {
140143
components: {
141144
ResizeBar,
145+
RotateBar,
142146
},
143147
props: {
144148
ratio: {
@@ -156,6 +160,10 @@ export default {
156160
isResize: {
157161
type: [Boolean],
158162
default: false,
163+
},
164+
isRotate: {
165+
type: [Boolean],
166+
default: true,
159167
}
160168
},
161169
@@ -177,6 +185,9 @@ export default {
177185
methods: {
178186
setImage(src, w, h) {
179187
this.src = src;
188+
if (!this.originSrc) {
189+
this.originSrc = this.src;
190+
}
180191
if (this.ratio.indexOf(':') > 0) {
181192
this.ratioW = this.ratio.split(':')[0];
182193
this.ratioH = this.ratio.split(':')[1];
@@ -217,14 +228,20 @@ export default {
217228
this.imgChangeRatio = this.width / this.natrualWidth;
218229
},
219230
231+
rotateImage(degress) {
232+
const data = canvasHelper.rotate(this.originSrc, degress, (data, w, h) => {
233+
this.setImage(data, w, h);
234+
});
235+
//this.src = src;
236+
},
237+
220238
setLayout(w, h) {
221239
let H = areaHeight,
222240
W = areaWidth,
223241
width = w,
224242
height = h,
225243
marginLeft = 0,
226244
marginTop = 0;
227-
228245
// caculate the image ratio
229246
let R = width / height;
230247
let Rs = W / H;

dist/lib/canvas-helper.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/drag.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/loading-gif.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)