-
Notifications
You must be signed in to change notification settings - Fork 323
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
4 changed files
with
79 additions
and
0 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,61 @@ | ||
<route lang="yaml"> | ||
meta: | ||
enabled: false | ||
</route> | ||
|
||
<script lang="ts" setup> | ||
import Cropper from 'cropperjs' | ||
import 'cropperjs/dist/cropper.css' | ||
import Alert from './components/alert.vue' | ||
let cropper: any = null | ||
const imageRef = ref() | ||
const cropImage = ref('') | ||
onMounted(() => { | ||
cropper = new Cropper(imageRef.value, { | ||
aspectRatio: 1, | ||
viewMode: 1, | ||
dragMode: 'move', | ||
}) | ||
}) | ||
function onCrop() { | ||
const canvas = cropper.getCroppedCanvas() | ||
cropImage.value = canvas.toDataURL() | ||
} | ||
function open(url: string) { | ||
window.open(url, '_blank') | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<Alert /> | ||
<PageHeader title="图片裁剪"> | ||
<template #content> | ||
<p style="margin-bottom: 0;"> | ||
安装命令:<ElTag>pnpm add cropperjs</ElTag> | ||
</p> | ||
</template> | ||
<ElButton @click="open('https://github.com/fengyuanchen/cropperjs')"> | ||
<template #icon> | ||
<SvgIcon name="i-ep:link" /> | ||
</template> | ||
访问 cropperjs | ||
</ElButton> | ||
</PageHeader> | ||
<PageMain> | ||
<div> | ||
<img ref="imageRef" src="@/assets/images/logo.png" class="block h-xl w-xl"> | ||
</div> | ||
<HButton @click="onCrop"> | ||
裁剪 | ||
</HButton> | ||
</PageMain> | ||
<PageMain v-if="cropImage"> | ||
<img :src="cropImage" class="block h-xs w-xs"> | ||
</PageMain> | ||
</div> | ||
</template> |