feat: add design features type

This commit is contained in:
IchliebedichZhu 2024-03-01 22:13:41 +00:00
parent 0d59f5c58f
commit 7ab19a6294
4 changed files with 25 additions and 6 deletions

View File

@ -2,17 +2,25 @@
* @Author: ShawnPhang
* @Date: 2022-02-22 15:06:14
* @Description:
* @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2024-01-11 17:36:44
* @LastEditors: ShawnPhang <https://m.palxp.cn>, Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditTime: 2024-03-01 20:55:51
*/
import store from '@/store'
import { getImage } from '../getImgDetail'
export default async function setItem2Data(item: any) {
export type TItem2DataParam = {
width: number
height: number
url: string
model?: string
}
export default async function setItem2Data(item: TItem2DataParam) {
const cloneItem = JSON.parse(JSON.stringify(item))
const { width: screenWidth, height: screenHeight } = store.getters.dPage
let { width: imgWidth, height: imgHeight } = item
if (!imgWidth || !imgHeight) {
const actual: any = await getImage(item.url)
const actual = await getImage(item.url)
cloneItem.width = imgWidth = actual.width
cloneItem.height = imgHeight = actual.height
}

View File

@ -11,7 +11,8 @@ import setImageData from '@/common/methods/DesignFeatures/setImage'
import wText from '@/components/modules/widgets/wText/wText.vue'
import wImage from '@/components/modules/widgets/wImage/wImage.vue'
import wSvg from '@/components/modules/widgets/wSvg/wSvg.vue'
export default async function(type: string, item: any, data: any) {
export default async function(type: string, item: TCommonItemData, data: Record<string, any>) {
let setting = data
if (type === 'text') {
!item.fontFamily && !item.color ? (setting = JSON.parse(JSON.stringify(wText.setting))) : (setting = item)

View File

@ -5,7 +5,7 @@
* @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2023-10-09 10:42:54
*/
export const getImage = (imgItem: string | File) => {
export const getImage = (imgItem: string | File): Promise<HTMLImageElement> => {
// 创建对象
const img = new Image()

10
src/types/global.d.ts vendored
View File

@ -7,3 +7,13 @@ type TCommResResult<T> = {
result: T
}
type TCommonItemData = {
fontFamily?: string
color?: string
fontSize: number
width?: number
fontWeight: number
value: TItem2DataParam
}