更新记录
1.1.4(2025-08-01)
下载此版本
新增增加水印功能
1.1.3(2025-05-24)
下载此版本
修复翻转后裁剪定位点不对问题;修复裁剪后保存图片会被拉伸问题;
1.1.2(2025-03-13)
下载此版本
增加保存图片时 quality:1 图片的质量为最高
查看更多
平台兼容性
uni-app(4.07)
Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
√ |
√ |
√ |
√ |
√ |
- |
√ |
- |
- |
微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
√ |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(4.07)
Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
- |
- |
- |
- |
- |
- |
chj-imgEdit 图片编辑器
平台兼容
H5 |
微信小程序 |
支付宝小程序 |
百度小程序 |
头条小程序 |
QQ 小程序 |
App |
√ |
√ |
未测 |
未测 |
未测 |
未测 |
√ |
代码演示
基本用法
<button @click="onClick">开启图片编辑</button>
<chj-imgEdit
ref="imgEdit"
:isAllCanvas="false"
@confirm="confirm"
@cancel="cancel"
@getLineLength="getLineLength"
@getRectPosition="getRectPosition"
@error="error" />
Vue/Nvue
import {ref} from "vue";
const imgEdit = ref(null);
function onClick() {
uni.chooseImage({
count: 1,
success: (res) => {
imgEdit.value.open({
// 底图路径
path: res.tempFilePaths[0],
// 取消是否有弹窗提示
isCancelToast: true,
// 取消弹窗提示内容
cancelText: '确定真的退出吗?',
// 确定是否有弹窗提示
isConfirmToast: true,
// 确定弹窗提示内容
confirmText: '决定好了吗?',
// 设置图标
iconPath: {
goForward_active: '/static/goForward.png',
},
// 设置涂鸦图标(根据下标匹配)
iconPathGraffiti: {
0: '/static/iconPathGraffiti-1.png',
},
// 水印配置项
watermarkConfig:{
text:'水印',
position: 'center',
color:'#fff',
x: 50,
y: 50,
size:20,
}
});
}
});
}
API
Props
参数 |
说明 |
类型 |
默认值 |
activeColor |
激活的颜色 |
string |
#FFCC33 |
isAllCanvas |
确定时是否保存整个画布(设为false只保存背景图片部分) |
Boolean |
true |
事件 Events
事件名 |
说明 |
回调参数 |
confirm |
确定 (回调参数为编辑完成的图片路径) |
path |
cancel |
取消 |
|
getLineLength |
获取横线的长度(单位px) |
length |
getRectPosition |
获取矩行的位置({x1,y1,x2,y2}) |
obj |
error |
图片生成失败 |
- |
使用说明
打开图片编辑器,需要 chj-imgEdit 中声明 ref 属性
<chj-imgEdit ref="chjImgEdit" @confirm="confirm" @cancel="cancel" />
this.$refs.chjImgEdit.open(options);
如果使用vue3语法,ref获取的组件下没有open方法可以使用以下方法解决。
import { getCurrentInstance } from 'vue';
const { proxy } = getCurrentInstance();
proxy.$refs.chjImgEdit.open();
options 参数说明
参数 |
说明 |
类型 |
默认值 |
path |
底图路径 |
string |
- |
isCancelToast |
取消是否有弹窗提示 |
boolean |
true |
cancelText |
取消弹窗提示内容 |
string |
内容未保存,确定退出吗? |
isConfirmToast |
确定是否有弹窗提示 |
boolean |
true |
confirmText |
确定弹窗提示内容 |
string |
确定完成编辑吗? |
iconPath |
设置图标 |
object |
- |
iconPathGraffiti |
设置涂鸦图标 |
object |
- |
watermarkConfig |
设置水印 |
object |
- |
iconPath 参数说明
参数 |
说明 |
类型 |
默认值 |
positionReset |
复位(放大倍率和偏移量重置) |
string |
- |
goForward_active |
前进可点击状态 |
string |
- |
goForward_inactive |
前进不可点击状态 |
string |
- |
retreat_active |
后退可点击状态 |
string |
- |
retreat_inactive |
后退不可点击状态 |
string |
- |
reset |
重置 |
string |
- |
close |
关闭 |
string |
- |
confirm |
确定 |
string |
- |
pen |
笔 |
string |
- |
rubber |
橡皮 |
string |
- |
iconPathGraffiti 参数说明
按下标设置图片路径
iconPathGraffiti:{
'0':'/static/iconPathGraffiti_1.png',
}
参数 |
说明 |
类型 |
默认值 |
0 |
涂鸦 |
string |
- |
1 |
矩形 |
string |
- |
2 |
圆形 |
string |
- |
3 |
横线 |
string |
- |
4 |
箭头 |
string |
- |
5 |
文本 |
string |
- |
6 |
裁剪 |
string |
- |
7 |
翻转 |
string |
- |
watermarkConfig 参数说明
参数 |
说明 |
类型 |
默认值 |
text |
水印文本 |
string |
当前日期,格式为YYYY-MM-DD |
position |
定位(top-left/top-right/bottom-left/bottom-right/center) |
string |
bottom-right |
x |
x轴位置(优先级高于position) |
number |
- |
y |
y轴位置(优先级高于position) |
number |
- |
size |
字体大小 |
number |
12 |
color |
字体颜色 |
string |
props的activeColor值 |