Browse Source

首次完成

szjcomo 3 years ago
parent
commit
a3b12d9cec
2 changed files with 194 additions and 1 deletions
  1. 46 1
      README.md
  2. 148 0
      index.vue

+ 46 - 1
README.md

@@ -1,3 +1,48 @@
 # image-cut-pc
 
-基于vue的图片裁剪插件
+基于vue的图片裁剪插件
+
+# 使用示例
+
+### 安装
+
+```js
+// 本项是基于vue-common-admin 框架开 中间用到了service服务
+// 1、在项目下安装 npm install vue-img-cutter
+// 2、在项目根目录下 mkdir addons
+// 3、git clone http://git.sizhijie.com/vue-addons/image-cut-pc.git image-cut-pc
+// 4、在vue中组件引入的方式使用
+```
+
+### 示例
+
+```js
+// 组件引入
+import imageCutComponent 	from '../../../addons/image-cut-pc/index.vue';
+import service 				from '@/service';
+
+// 组件使用
+<imageCutComponent @success="handleImageCutSuccess" @error="handleImageCutError" ref="image_cut_xxx"/>
+
+// 定义图片裁剪成功后的方法
+handleImageCutSuccess:function (filedata,params = {}) {
+	console.log(filedata,params);
+}
+//定义图片裁剪失败的方法
+handleImageCutError:function(err) {
+	console.log(err)
+}
+
+//以element ui 2图片上传为例
+//打开图片裁剪的方法
+uploadImageHandle:async function(params) {
+	let base64Image = await service.image.file2Base64(params.file);
+	this.$refs.image_cut_xxx.cutOpen({name:params.file.name,src:base64Image},params);	
+}
+```
+
+# 开发日志
+
+__2021年2月27日__
+
+* 完成插件单独分离功能,完成插件开发和安装示例

+ 148 - 0
index.vue

@@ -0,0 +1,148 @@
+<template>
+	<div class="image-cut">
+		<ImgCutter @cutDown="handleCutDown" ref="imageCut" :crossOrigin="true" :originalGraph="false" :cutWidth="400" :cutHeight="260" v-show="cutImageShow" @on-clear-all="handleCutClearAll" :showChooseBtn="false" :lockScroll="false" :box-width="boxWidth" :box-height="boxHeight" :tool="true" @error="handleCutError">
+			<span slot="open"></span>
+		</ImgCutter>
+	</div>
+</template>
+<script>
+import service 		from '@/service';
+import ImgCutter 	from 'vue-img-cutter';
+export default {
+	name: 'image-cut',
+	components: {ImgCutter},
+	props:{
+		/**
+		 * [boxWidth 弹出层宽度]
+		 * @type {Object}
+		 */
+		boxWidth:{
+			type:Number,
+			default:service.dialogMax(0.9,0.7).width
+		},
+		/**
+		 * [boxHeight 弹出层高度]
+		 * @type {Object}
+		 */
+		boxHeight:{
+			type:Number,
+			default:service.dialogMax(0.7,0.7).height
+		},
+	},
+	data() {
+		return {
+			/**
+			 * [cutImageShow 是否显示图片裁剪功能]
+			 * @type {Boolean}
+			 */
+			cutImageShow:false,
+			/**
+			 * [openParams 设置参数]
+			 * @type {Object}
+			 */
+			openParams:{}
+		};
+	},
+	methods:{
+		/**
+		 * [initialize 初始化]
+		 * @author    szjcomo
+		 * @date   		2021-02-22
+		 * @return {[type]}     [description]
+		 */
+		initialize:function() {
+			let that = this;
+		},
+		/**
+		 * [cutOpen 开始图片裁剪]
+		 * @author    szjcomo
+		 * @date   		2021-02-22
+		 * @param  {Object}     data [description]
+		 * @return {[type]}          [description]
+		 */
+		cutOpen:function(data = {},params = {}) {
+			let that = this;
+			that.cutImageShow = true;
+			that.openParams = params;
+			that.$refs.imageCut.handleOpen(data);
+		},
+		/**
+		 * [handleCutDown 图片裁剪完成后回调函数]
+		 * @author    szjcomo
+		 * @date   		2021-02-22
+		 * @param  {[type]}     data [description]
+		 * @return {[type]}          [description]
+		 */
+		handleCutDown:function(data) {
+			let that = this;
+			that.cutImageShow = false;
+			that.$emit('success',data,that.openParams);
+		},
+		/**
+		 * [handleCutClearAll 清空画布回调函数]
+		 * @author    szjcomo
+		 * @date   		2021-02-22
+		 * @return {[type]}     [description]
+		 */
+		handleCutClearAll:function() {
+			let that = this;
+			that.cutImageShow = false;
+		},
+		/**
+		 * [handleCutError 图片裁剪错误信息]
+		 * @author    szjcomo
+		 * @date   		2021-02-22
+		 * @param  {[type]}     err [description]
+		 * @return {[type]}         [description]
+		 */
+		handleCutError:function(err) {
+			let that = this;
+			that.$emit('error',err);
+		}
+	},
+	//计算属性
+	computed:{
+
+	},
+	//侦听属性
+	watch:{
+
+	},
+	//实例刚在内存中被创建出来,此时,还没有初始化好 data 和 methods 属性
+	beforeCreate:function(){
+
+	},
+	//实例已经在内存中创建OK,此时 data 和 methods 已经创建OK,此时还没有开始 编译模板
+	created:function(){
+
+	},
+	//此时已经完成了模板的编译,但是还没有挂载到页面中
+	beforeMount:function(){
+
+	},
+	//此时,已经将编译好的模板,挂载到了页面指定的容器中显示
+	mounted:function(){
+		let that = this;
+		that.initialize();
+	},
+	//状态更新之前执行此函数, 此时 data 中的状态值是最新的,但是界面上显示的 数据还是旧的,因为此时还没有开始重新渲染DOM节点
+	beforeUpdate:function(){
+
+	},
+	//实例更新完毕之后调用此函数,此时 data 中的状态值 和 界面上显示的数据,都已经完成了更新,界面已经被重新渲染好了!
+	updated:function(){
+
+	},
+	//实例销毁之前调用。在这一步,实例仍然完全可用。
+	beforeDestroy:function(){
+
+	},
+	//Vue 实例销毁后调用。调用后,Vue 实例指示的所有东西都会解绑定,所有的事件监听器会被移除,所有的子实例也会被销毁。
+	destroyed:function(){
+
+	}
+}
+</script>
+<style>
+.image-cut .mask{z-index: 9999;}
+</style>