mirror of
https://github.com/palxiao/poster-design.git
synced 2025-07-15 16:02:19 +08:00
style: cut image
This commit is contained in:
parent
53df4edd76
commit
4dd687d5a6
@ -3,7 +3,7 @@
|
|||||||
* @Date: 2023-07-11 23:50:22
|
* @Date: 2023-07-11 23:50:22
|
||||||
* @Description: 抠图组件
|
* @Description: 抠图组件
|
||||||
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
||||||
* @LastEditTime: 2023-10-05 16:19:11
|
* @LastEditTime: 2023-10-07 15:48:27
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<el-dialog v-model="show" title="AI 智能抠图" width="650" @close="handleClose">
|
<el-dialog v-model="show" title="AI 智能抠图" width="650" @close="handleClose">
|
||||||
@ -31,7 +31,7 @@
|
|||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button v-show="rawImage && toolModel" @click="clear">重新选择图片</el-button>
|
<el-button v-show="rawImage && toolModel" @click="clear">重新选择图片</el-button>
|
||||||
<el-button v-show="cutImage && toolModel" type="primary" plain @click="download"> 下载 </el-button>
|
<el-button v-show="cutImage && toolModel" type="primary" plain @click="download"> 下载 </el-button>
|
||||||
<el-button v-show="cutImage && !toolModel" type="primary" plain @click="cutDone"> 完成 </el-button>
|
<el-button v-show="cutImage && !toolModel" v-loading="loading" type="primary" plain @click="cutDone"> {{ loading ? '上传中..' : '完成' }} </el-button>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
@ -44,7 +44,10 @@ import { ElProgress } from 'element-plus'
|
|||||||
import { UploadFilled } from '@element-plus/icons-vue'
|
import { UploadFilled } from '@element-plus/icons-vue'
|
||||||
import uploader from '@/components/common/Uploader/index.vue'
|
import uploader from '@/components/common/Uploader/index.vue'
|
||||||
import _dl from '@/common/methods/download'
|
import _dl from '@/common/methods/download'
|
||||||
import * as api from '@/api/ai'
|
import api from '@/api'
|
||||||
|
import Qiniu from '@/common/methods/QiNiu'
|
||||||
|
import _config from '@/config'
|
||||||
|
import { getImage } from '@/common/methods/getImgDetail'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: { uploader, UploadFilled, ElProgress },
|
components: { uploader, UploadFilled, ElProgress },
|
||||||
@ -61,6 +64,7 @@ export default defineComponent({
|
|||||||
progress: 0,
|
progress: 0,
|
||||||
progressText: '',
|
progressText: '',
|
||||||
toolModel: true,
|
toolModel: true,
|
||||||
|
loading: false,
|
||||||
})
|
})
|
||||||
let fileName: string = 'unknow'
|
let fileName: string = 'unknow'
|
||||||
let isRuning: boolean = false
|
let isRuning: boolean = false
|
||||||
@ -77,7 +81,7 @@ export default defineComponent({
|
|||||||
state.rawImage = URL.createObjectURL(file)
|
state.rawImage = URL.createObjectURL(file)
|
||||||
fileName = file.name
|
fileName = file.name
|
||||||
// 返回抠图结果
|
// 返回抠图结果
|
||||||
const result: any = await api.upload(file, (up: number, dp: number) => {
|
const result: any = await api.ai.upload(file, (up: number, dp: number) => {
|
||||||
if (dp) {
|
if (dp) {
|
||||||
state.progressText = dp === 100 ? '' : '导入中..'
|
state.progressText = dp === 100 ? '' : '导入中..'
|
||||||
state.progress = dp
|
state.progress = dp
|
||||||
@ -94,6 +98,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const open = (file: File) => {
|
const open = (file: File) => {
|
||||||
|
state.loading = false
|
||||||
state.show = true
|
state.show = true
|
||||||
store.commit('setShowMoveable', false)
|
store.commit('setShowMoveable', false)
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
@ -132,10 +137,17 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cutDone = async () => {
|
const cutDone = async () => {
|
||||||
|
state.loading = true
|
||||||
const response = await fetch(state.cutImage)
|
const response = await fetch(state.cutImage)
|
||||||
const buffer = await response.arrayBuffer()
|
const buffer = await response.arrayBuffer()
|
||||||
const file = new File([buffer], `cut_image_${Math.random()}.png`)
|
const file = new File([buffer], `cut_image_${Math.random()}.png`)
|
||||||
emit('done', file)
|
// upload
|
||||||
|
const qnOptions = { bucket: 'xp-design', prePath: 'user' }
|
||||||
|
const result = await Qiniu.upload(file, qnOptions)
|
||||||
|
const { width, height } = await getImage(file)
|
||||||
|
const url = _config.IMG_URL + result.key
|
||||||
|
await api.material.addMyPhoto({ width, height, url })
|
||||||
|
emit('done', url)
|
||||||
state.show = false
|
state.show = false
|
||||||
handleClose()
|
handleClose()
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* @Date: 2022-02-11 18:48:23
|
* @Date: 2022-02-11 18:48:23
|
||||||
* @Description: 组件列表
|
* @Description: 组件列表
|
||||||
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
||||||
* @LastEditTime: 2023-10-04 00:43:54
|
* @LastEditTime: 2023-10-07 15:06:23
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
@ -12,6 +12,7 @@
|
|||||||
<i class="icon sd-w-qrcode" />
|
<i class="icon sd-w-qrcode" />
|
||||||
<div class="text"><span>二维码</span><span class="desc">在设计中使用风格化二维码</span></div>
|
<div class="text"><span>二维码</span><span class="desc">在设计中使用风格化二维码</span></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="header">其它</div>
|
||||||
<div class="item" @click="openImageCutout">
|
<div class="item" @click="openImageCutout">
|
||||||
<i class="icon sd-w-table" />
|
<i class="icon sd-w-table" />
|
||||||
<div class="text"><span>AI抠图</span> <span class="desc">上传图像一键去除背景</span></div>
|
<div class="text"><span>AI抠图</span> <span class="desc">上传图像一键去除背景</span></div>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* @Date: 2021-08-09 11:41:53
|
* @Date: 2021-08-09 11:41:53
|
||||||
* @Description:
|
* @Description:
|
||||||
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
||||||
* @LastEditTime: 2023-10-05 16:13:56
|
* @LastEditTime: 2023-10-07 15:46:30
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<div id="w-image-style">
|
<div id="w-image-style">
|
||||||
@ -73,8 +73,6 @@ import layerIconList from '@/assets/data/LayerIconList'
|
|||||||
import alignIconList from '@/assets/data/AlignListData'
|
import alignIconList from '@/assets/data/AlignListData'
|
||||||
import picBox from '@/components/business/picture-selector'
|
import picBox from '@/components/business/picture-selector'
|
||||||
import imageCutout from '@/components/business/image-cutout'
|
import imageCutout from '@/components/business/image-cutout'
|
||||||
import Qiniu from '@/common/methods/QiNiu'
|
|
||||||
import _config from '@/config'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: NAME,
|
name: NAME,
|
||||||
@ -243,6 +241,7 @@ export default {
|
|||||||
openPicBox() {
|
openPicBox() {
|
||||||
this.$refs.picBox.open()
|
this.$refs.picBox.open()
|
||||||
},
|
},
|
||||||
|
// 打开抠图
|
||||||
openImageCutout() {
|
openImageCutout() {
|
||||||
fetch(this.innerElement.imgUrl)
|
fetch(this.innerElement.imgUrl)
|
||||||
.then((response) => response.blob())
|
.then((response) => response.blob())
|
||||||
@ -255,13 +254,10 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 完成抠图
|
// 完成抠图
|
||||||
async cutImageDone(file) {
|
async cutImageDone(url) {
|
||||||
const qnOptions = { bucket: 'xp-design', prePath: 'user' }
|
setTimeout(() => {
|
||||||
const result = await Qiniu.upload(file, qnOptions)
|
this.innerElement.imgUrl = url
|
||||||
const { width, height } = await getImage(file)
|
}, 300)
|
||||||
const url = _config.IMG_URL + result.key
|
|
||||||
await api.material.addMyPhoto({ width, height, url })
|
|
||||||
this.innerElement.imgUrl = url
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user