-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
907 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/nutui-taro-demo/src/business/pages/avatarcropper/index.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
navigationBarTitleText: 'AvatarCropper' | ||
}; |
50 changes: 50 additions & 0 deletions
50
packages/nutui-taro-demo/src/business/pages/avatarcropper/index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<template> | ||
<div class="demo barrage-demo" :class="{ web: env === 'WEB' }"> | ||
<Header v-if="env === 'WEB'" /> | ||
<h2>基础用法</h2> | ||
<nut-cell> | ||
<nut-avatar-cropper @confirm="cutImage"> | ||
<nut-avatar size="large"> | ||
<img :src="imageUrl" /> | ||
</nut-avatar> | ||
</nut-avatar-cropper> | ||
</nut-cell> | ||
<h2>裁剪区域toolbar插槽</h2> | ||
<nut-cell> | ||
<nut-avatar-cropper ref="avatarCropperRef" toolbar-position="top" edit-text="修改" @confirm="cutImage"> | ||
<nut-avatar size="large"> | ||
<img :src="imageUrl" /> | ||
</nut-avatar> | ||
<template #toolbar> | ||
<div class="toolbar"> | ||
<nut-button type="primary" @click="avatarCropperRef.cancel()">取消</nut-button> | ||
<nut-button type="primary" @click="avatarCropperRef.reset()">重置</nut-button> | ||
<nut-button type="primary" @click="avatarCropperRef.rotate()">旋转</nut-button> | ||
<nut-button type="primary" @click="avatarCropperRef.confirm()">确认</nut-button> | ||
</div> | ||
</template> | ||
</nut-avatar-cropper> | ||
</nut-cell> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref } from 'vue'; | ||
import Taro from '@tarojs/taro'; | ||
import Header from '../../../components/header.vue'; | ||
const env = Taro.getEnv(); | ||
const imageUrl = ref( | ||
'https://img12.360buyimg.com/imagetools/jfs/t1/196430/38/8105/14329/60c806a4Ed506298a/e6de9fb7b8490f38.png' | ||
); | ||
const avatarCropperRef = ref(); | ||
const cutImage = (url: string) => { | ||
imageUrl.value = url; | ||
}; | ||
</script> | ||
|
||
<style> | ||
.toolbar { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import Taro from '@tarojs/taro'; | ||
import CanvasContext = Taro.CanvasContext; | ||
|
||
const compareVersion = (v1Old: string, v2Old: string) => { | ||
let v1 = v1Old.split('.'); | ||
let v2 = v2Old.split('.'); | ||
const len = Math.max(v1.length, v2.length); | ||
|
||
while (v1.length < len) { | ||
v1.push('0'); | ||
} | ||
while (v2.length < len) { | ||
v2.push('0'); | ||
} | ||
|
||
for (let i = 0; i < len; i++) { | ||
const num1 = parseInt(v1[i]); | ||
const num2 = parseInt(v2[i]); | ||
|
||
if (num1 > num2) { | ||
return 1; | ||
} else if (num1 < num2) { | ||
return -1; | ||
} | ||
} | ||
|
||
return 0; | ||
}; | ||
|
||
const isWeapp = () => { | ||
return process.env.TARO_ENV === 'weapp'; | ||
}; | ||
|
||
////////////////////////////////////////////////////////////////////////////////// | ||
//////// 微信小程序自1.9.90起废除若干个CanvasContext的函数,改为属性,以下为兼容代码 | ||
////////////////////////////////////////////////////////////////////////////////// | ||
|
||
function _easyCanvasContextBase( | ||
systemInfo: any, | ||
lowCallback: () => void, | ||
highCallback: () => void, | ||
targetVersion: string = '1.9.90' | ||
) { | ||
if (isWeapp() && compareVersion(systemInfo.SDKVersion, targetVersion) >= 0) { | ||
highCallback(); | ||
} else { | ||
lowCallback(); | ||
} | ||
} | ||
/** | ||
* | ||
* 基础库 1.9.90 开始支持,低版本需做兼容处理。填充颜色。用法同 CanvasContext.setFillStyle()。 | ||
* @param systemInfo | ||
* @param canvasContext | ||
* @param color | ||
*/ | ||
function easySetStrokeStyle(systemInfo: any, canvasContext: CanvasContext, color: string | CanvasGradient) { | ||
_easyCanvasContextBase( | ||
systemInfo, | ||
() => { | ||
canvasContext.setStrokeStyle(color); | ||
console.log('???'); | ||
}, | ||
() => { | ||
if (typeof color === 'string') { | ||
canvasContext.strokeStyle = color; | ||
} | ||
console.log('2333'); | ||
} | ||
); | ||
} | ||
|
||
function easySetLineWidth(systemInfo: any, canvasContext: CanvasContext, lineWidth: number) { | ||
_easyCanvasContextBase( | ||
systemInfo, | ||
() => { | ||
canvasContext.setLineWidth(lineWidth); | ||
}, | ||
() => { | ||
canvasContext.lineWidth = lineWidth; | ||
} | ||
); | ||
} | ||
|
||
function easySetFillStyle(systemInfo: any, canvasContext: CanvasContext, color: string | CanvasGradient) { | ||
_easyCanvasContextBase( | ||
systemInfo, | ||
() => { | ||
canvasContext.setFillStyle(color); | ||
}, | ||
() => { | ||
if (typeof color === 'string') { | ||
canvasContext.fillStyle = color; | ||
} | ||
} | ||
); | ||
} | ||
|
||
export { easySetStrokeStyle, easySetLineWidth, easySetFillStyle }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.