mirror of
https://github.com/palxiao/poster-design.git
synced 2025-07-03 03:56:41 +08:00
Merge branch 'main' into feat-upgrade-vue3
This commit is contained in:
commit
d21ce04738
10
README.md
10
README.md
@ -67,7 +67,15 @@ npm run serve
|
||||
- [qr-code-styling](https://qr-code-styling.com/): 风格化二维码
|
||||
- [rembg](https://github.com/danielgatis/rembg): 图片抠图,使用 u2net 预训练模型
|
||||
|
||||
或许你在工作中有类似的需求,或许你对开发编辑器感兴趣,也希望这个项目能给到你一些微薄帮助!
|
||||
### 友情赞助商
|
||||
|
||||
[](https://dooring.vip/)
|
||||
|
||||
### 交流群
|
||||
|
||||
| 作者微信:备注加群 | 公众号 |
|
||||
| --- | --- |
|
||||
|  |  |
|
||||
|
||||
### `Star`
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
* @Date: 2021-08-27 15:16:07
|
||||
* @Description: 素材列表,主要用于文字组合列表
|
||||
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
||||
* @LastEditTime: 2024-01-11 17:59:57
|
||||
* @LastEditTime: 2024-02-29 16:54:28
|
||||
-->
|
||||
<template>
|
||||
<div class="wrap">
|
||||
@ -241,14 +241,14 @@ export default defineComponent({
|
||||
background: #f8fafc;
|
||||
}
|
||||
&__img {
|
||||
cursor: pointer;
|
||||
cursor: grab;
|
||||
width: 142px;
|
||||
height: 142px;
|
||||
padding: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
&__img-thumb {
|
||||
cursor: pointer;
|
||||
cursor: grab;
|
||||
width: 90px;
|
||||
height: 90px;
|
||||
background: #f8fafc;
|
||||
|
@ -3,7 +3,7 @@
|
||||
* @Date: 2021-08-27 15:16:07
|
||||
* @Description: 素材列表
|
||||
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
||||
* @LastEditTime: 2023-11-24 11:14:28
|
||||
* @LastEditTime: 2024-02-29 16:49:59
|
||||
-->
|
||||
<template>
|
||||
<div class="wrap">
|
||||
@ -217,14 +217,14 @@ export default defineComponent({
|
||||
background: #f8fafc;
|
||||
}
|
||||
&__img {
|
||||
cursor: pointer;
|
||||
cursor: grab;
|
||||
width: 142px;
|
||||
height: 142px;
|
||||
padding: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
&__img-thumb {
|
||||
cursor: pointer;
|
||||
cursor: grab;
|
||||
width: 90px;
|
||||
height: 90px;
|
||||
background: #f8fafc;
|
||||
|
@ -70,7 +70,7 @@ export default {
|
||||
{
|
||||
text: '+ 添加文字',
|
||||
fontSize: 60,
|
||||
fontWeight: 'bold',
|
||||
fontWeight: 'normal',
|
||||
},
|
||||
// {
|
||||
// text: '+ 添加文字',
|
||||
@ -97,8 +97,7 @@ export default {
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
// Color variables (appears count calculates by raw css)
|
||||
@color0: #3b74f1; // Appears 2 times
|
||||
// @color0: #3b74f1;
|
||||
|
||||
#text-list-wrap {
|
||||
display: flex;
|
||||
|
@ -3,7 +3,7 @@
|
||||
* @Date: 2022-02-23 15:48:52
|
||||
* @Description: 图片列表组件 Bookshelf Layout
|
||||
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
||||
* @LastEditTime: 2023-12-11 11:12:04
|
||||
* @LastEditTime: 2024-02-29 16:52:37
|
||||
-->
|
||||
<template>
|
||||
<ul ref="listRef" class="img-list-wrap" :style="{ paddingBottom: isShort ? '15px' : '200px' }" @scroll="scrollEvent($event)">
|
||||
@ -207,7 +207,7 @@ export default defineComponent({
|
||||
&__img {
|
||||
// background: #f1f2f4;
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
cursor: grab;
|
||||
// margin: 0 6px 2px 0;
|
||||
margin-bottom: 3px;
|
||||
border-radius: 2px;
|
||||
|
@ -57,7 +57,9 @@ export default defineComponent({
|
||||
|
||||
onMounted(() => {
|
||||
if (props.modelValue) {
|
||||
state.innerColor = props.modelValue + (props.modelValue.length === 7 ? 'ff' : '')
|
||||
let fixColor = props.modelValue + (props.modelValue.length === 7 ? 'ff' : '')
|
||||
// 当前@palxp/color-picker对部分小写16进制颜色处理有异常,统一转为大写
|
||||
state.innerColor = fixColor.toLocaleUpperCase()
|
||||
}
|
||||
})
|
||||
const dropColor = async (e: any) => {
|
||||
|
@ -49,15 +49,17 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
// 文本组件
|
||||
const NAME = 'w-text'
|
||||
|
||||
import { mapGetters, mapActions } from 'vuex'
|
||||
import { defineComponent, reactive, toRefs, computed, onUpdated, watch, onMounted, ref } from 'vue'
|
||||
import { useStore } from 'vuex'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { fontWithDraw } from '@/utils/widgets/loadFontRule'
|
||||
import getGradientOrImg from './getGradientOrImg.ts'
|
||||
|
||||
export default {
|
||||
export default defineComponent({
|
||||
name: NAME,
|
||||
setting: {
|
||||
name: '文本',
|
||||
@ -97,116 +99,122 @@ export default {
|
||||
},
|
||||
},
|
||||
props: ['params', 'parent'],
|
||||
data() {
|
||||
return {
|
||||
setup(props) {
|
||||
const store = useStore()
|
||||
const route = useRoute()
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
editable: false,
|
||||
loadFontDone: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['dActiveElement']),
|
||||
isDraw() {
|
||||
return this.$route.name === 'Draw' && fontWithDraw
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
params: {
|
||||
async handler(nval) {
|
||||
this.updateText()
|
||||
if (this.loading) {
|
||||
})
|
||||
const widget = ref(null)
|
||||
const editWrap = ref(null)
|
||||
|
||||
const dActiveElement = computed(() => store.getters.dActiveElement)
|
||||
const isDraw = computed(() => route.name === 'Draw' && fontWithDraw)
|
||||
|
||||
onUpdated(() => {
|
||||
updateRecord()
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
updateRecord()
|
||||
props.params.transform && (widget.value.style.transform = props.params.transform)
|
||||
props.params.rotate && (widget.value.style.transform += `translate(0px, 0px) rotate(${props.params.rotate}) scale(1, 1)`)
|
||||
// store.commit('updateRect')
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.params,
|
||||
async (nval) => {
|
||||
updateText()
|
||||
if (state.loading) {
|
||||
return
|
||||
}
|
||||
let font = nval.fontClass
|
||||
const isDone = font.value === this.loadFontDone
|
||||
const isDone = font.value === state.loadFontDone
|
||||
|
||||
if (font.url && !isDone) {
|
||||
if (font.id && this.isDraw) {
|
||||
if (font.id && isDraw.value) {
|
||||
// 如果为绘制模式,且开启了字体抽取,那么会跳过加载字体url的逻辑
|
||||
// 此前该功能在demo中存在换行bug,实际上是由于抽取字体时忽略了空格导致的
|
||||
this.loading = false
|
||||
state.loading = false
|
||||
return
|
||||
}
|
||||
this.loading = !this.isDraw
|
||||
state.loading = !isDraw.value
|
||||
const loadFont = new window.FontFace(font.value, `url(${font.url})`)
|
||||
await loadFont.load()
|
||||
document.fonts.add(loadFont)
|
||||
this.loadFontDone = font.value
|
||||
this.loading = false
|
||||
state.loadFontDone = font.value
|
||||
state.loading = false
|
||||
} else {
|
||||
this.loading = false
|
||||
state.loading = false
|
||||
}
|
||||
},
|
||||
immediate: true,
|
||||
deep: true,
|
||||
},
|
||||
editable(value) {
|
||||
this.updateWidgetData({
|
||||
uuid: this.params.uuid,
|
||||
key: 'editable',
|
||||
value,
|
||||
pushHistory: false,
|
||||
})
|
||||
},
|
||||
},
|
||||
updated() {
|
||||
this.updateRecord()
|
||||
},
|
||||
async mounted() {
|
||||
this.updateRecord()
|
||||
// await this.$nextTick()
|
||||
this.params.transform && (this.$refs.widget.style.transform = this.params.transform)
|
||||
this.params.rotate && (this.$refs.widget.style.transform += `translate(0px, 0px) rotate(${this.params.rotate}) scale(1, 1)`)
|
||||
// this.$store.commit('updateRect')
|
||||
},
|
||||
methods: {
|
||||
...mapActions(['updateWidgetData', 'pushHistory']),
|
||||
getGradientOrImg,
|
||||
updateRecord() {
|
||||
if (this.dActiveElement.uuid === this.params.uuid) {
|
||||
let record = this.dActiveElement.record
|
||||
record.width = this.$refs.widget.offsetWidth
|
||||
record.height = this.$refs.widget.offsetHeight
|
||||
record.minWidth = this.params.fontSize
|
||||
record.minHeight = this.params.fontSize * this.params.lineHeight
|
||||
this.writingText()
|
||||
{ immediate: true, deep: true },
|
||||
)
|
||||
|
||||
watch(
|
||||
() => state.editable,
|
||||
(value) => {
|
||||
store.dispatch('updateWidgetData', {
|
||||
uuid: props.params.uuid,
|
||||
key: 'editable',
|
||||
value,
|
||||
pushHistory: false,
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
function updateRecord() {
|
||||
if (dActiveElement.value.uuid === props.params.uuid) {
|
||||
let record = dActiveElement.value.record
|
||||
record.width = widget.value.offsetWidth
|
||||
record.height = widget.value.offsetHeight
|
||||
record.minWidth = props.params.fontSize
|
||||
record.minHeight = props.params.fontSize * props.params.lineHeight
|
||||
writingText()
|
||||
}
|
||||
},
|
||||
updateText(e) {
|
||||
const value = e ? e.target.innerHTML : this.params.text.replace(/\n/g, '<br/>')
|
||||
// const value = (e ? e.target.innerText : this.params.text).replace(/<br\/>/g, '\r\n').replace(/ /g, ' ')
|
||||
if (value !== this.params.text) {
|
||||
this.updateWidgetData({
|
||||
uuid: this.params.uuid,
|
||||
}
|
||||
|
||||
function updateText(e) {
|
||||
const value = e ? e.target.innerHTML : props.params.text.replace(/\n/g, '<br/>')
|
||||
// const value = (e ? e.target.innerText : props.params.text).replace(/<br\/>/g, '\r\n').replace(/ /g, ' ')
|
||||
if (value !== props.params.text) {
|
||||
store.dispatch('updateWidgetData', {
|
||||
uuid: props.params.uuid,
|
||||
key: 'text',
|
||||
value,
|
||||
pushHistory: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
writingText(e) {
|
||||
// this.updateText(e)
|
||||
}
|
||||
|
||||
function writingText(e) {
|
||||
// updateText(e)
|
||||
// TODO: 修正文字选框高度
|
||||
const el = this.$refs.editWrap || this.$refs.widget
|
||||
this.updateWidgetData({
|
||||
uuid: this.params.uuid,
|
||||
const el = editWrap.value || widget.value
|
||||
store.dispatch('updateWidgetData', {
|
||||
uuid: props.params.uuid,
|
||||
key: 'height',
|
||||
value: el.offsetHeight,
|
||||
pushHistory: false,
|
||||
})
|
||||
this.$store.commit('updateRect')
|
||||
},
|
||||
writeDone(e) {
|
||||
this.editable = false
|
||||
store.commit('updateRect')
|
||||
}
|
||||
|
||||
function writeDone(e) {
|
||||
state.editable = false
|
||||
setTimeout(() => {
|
||||
this.pushHistory('文字修改')
|
||||
store.dispatch('pushHistory', '文字修改')
|
||||
}, 100)
|
||||
this.updateText(e)
|
||||
},
|
||||
dblclickText(e) {
|
||||
// this.$store.commit('setShowMoveable', false)
|
||||
this.editable = true
|
||||
const el = this.$refs.editWrap || this.$refs.widget
|
||||
updateText(e)
|
||||
}
|
||||
|
||||
function dblclickText(e) {
|
||||
// store.commit('setShowMoveable', false)
|
||||
state.editable = true
|
||||
const el = editWrap.value || widget.value
|
||||
setTimeout(() => {
|
||||
el.focus()
|
||||
if (document.selection) {
|
||||
@ -220,9 +228,21 @@ export default {
|
||||
window.getSelection().addRange(range)
|
||||
}
|
||||
}, 100)
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
getGradientOrImg,
|
||||
updateRecord,
|
||||
writingText,
|
||||
updateText,
|
||||
writeDone,
|
||||
dblclickText,
|
||||
widget,
|
||||
editWrap,
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@ -247,13 +267,4 @@ export default {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
// @font-face {
|
||||
// font-family: 'FONT-AZPPT';
|
||||
// font-display: swap;
|
||||
// src: url('./AZPPT.ttf') format('truetype');
|
||||
// }
|
||||
// .FONT-AZPPT {
|
||||
// font-family: 'FONT-AZPPT';
|
||||
// }
|
||||
</style>
|
||||
|
@ -34,7 +34,7 @@
|
||||
<!-- <color-select v-model="innerElement.backgroundColor" label="背景颜色" @finish="(value) => finish('backgroundColor', value)" /> -->
|
||||
</div>
|
||||
<div class="line-layout style-item">
|
||||
<effect-wrap v-model="innerElement.textEffects" :data="innerElement" :degree="innerElement.degree" @select="testEffect" />
|
||||
<effect-wrap v-model="innerElement.textEffects" :data="innerElement" :degree="innerElement.degree" @select="selectTextEffect" />
|
||||
</div>
|
||||
<icon-item-select class="style-item" :data="layerIconList" @finish="layerAction" />
|
||||
<icon-item-select class="style-item" :data="alignIconList" @finish="alignAction" />
|
||||
@ -48,13 +48,13 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
// 文本组件样式
|
||||
const NAME = 'w-text-style'
|
||||
// import api from '@/api'
|
||||
// import _config from '@/config'
|
||||
import { mapGetters, mapActions } from 'vuex'
|
||||
import { styleIconList1, styleIconList2, alignIconList } from '../../../../assets/data/TextIconsData'
|
||||
import { defineComponent, reactive, toRefs, computed, watch, nextTick, onMounted } from 'vue'
|
||||
import { useStore } from 'vuex'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { styleIconList1, styleIconList2, alignIconList } from '@/assets/data/TextIconsData'
|
||||
import layerIconList from '@/assets/data/LayerIconList'
|
||||
import numberInput from '../../settings/numberInput.vue'
|
||||
import numberSlider from '../../settings/numberSlider.vue'
|
||||
@ -66,193 +66,191 @@ import effectWrap from '../../settings/EffectSelect/TextWrap.vue'
|
||||
import { useFontStore } from '@/common/methods/fonts'
|
||||
import usePageFontsFilter from './pageFontsFilter.ts'
|
||||
|
||||
export default {
|
||||
export default defineComponent({
|
||||
name: NAME,
|
||||
components: { numberInput, colorSelect, iconItemSelect, textInputArea, valueSelect, effectWrap, numberSlider },
|
||||
data() {
|
||||
return {
|
||||
activeNames: [],
|
||||
innerElement: {},
|
||||
tag: false,
|
||||
ingoreKeys: ['left', 'top', 'name', 'width', 'height', 'text', 'color', 'backgroundColor'],
|
||||
fontSizeList: [12, 14, 24, 26, 28, 30, 36, 48, 60, 72, 96, 108, 120, 140, 180, 200, 250, 300, 400, 500],
|
||||
fontClassList: [], // 不能设空字体系统默认字体,因为截图服务的默认字体无法保证一致
|
||||
lineHeightList: [1, 1.5, 2],
|
||||
letterSpacingList: [0, 10, 25, 50, 75, 100, 200],
|
||||
layerIconList,
|
||||
styleIconList1,
|
||||
styleIconList2,
|
||||
alignIconList,
|
||||
components: { numberInput, colorSelect, iconItemSelect, textInputArea, valueSelect, effectWrap, numberSlider },
|
||||
setup() {
|
||||
const store = useStore()
|
||||
const route = useRoute()
|
||||
const state = reactive({
|
||||
activeNames: [],
|
||||
innerElement: {},
|
||||
tag: false,
|
||||
ingoreKeys: ['left', 'top', 'name', 'width', 'height', 'text', 'color', 'backgroundColor'],
|
||||
fontSizeList: [12, 14, 24, 26, 28, 30, 36, 48, 60, 72, 96, 108, 120, 140, 180, 200, 250, 300, 400, 500],
|
||||
fontClassList: [], // 不能设空字体系统默认字体,因为截图服务的默认字体无法保证一致
|
||||
lineHeightList: [1, 1.5, 2],
|
||||
letterSpacingList: [0, 10, 25, 50, 75, 100, 200],
|
||||
layerIconList,
|
||||
styleIconList1,
|
||||
styleIconList2,
|
||||
alignIconList,
|
||||
})
|
||||
const dActiveElement = computed(() => store.getters.dActiveElement)
|
||||
const dMoving = computed(() => store.getters.dMoving)
|
||||
// const isDraw = computed(() => route.name === 'Draw')
|
||||
|
||||
watch(() => dActiveElement.value, () => {
|
||||
change()
|
||||
}, { deep: true })
|
||||
|
||||
watch(() => state.innerElement, () => {
|
||||
changeValue()
|
||||
}, { deep: true })
|
||||
|
||||
let timer: any = null
|
||||
|
||||
onMounted(() => {
|
||||
change()
|
||||
setTimeout(() => {
|
||||
loadFonts()
|
||||
}, 100)
|
||||
})
|
||||
|
||||
function change() {
|
||||
if (timer) {
|
||||
return
|
||||
}
|
||||
timer = true
|
||||
setTimeout(() => {
|
||||
timer = null
|
||||
}, 300)
|
||||
state.tag = true
|
||||
state.innerElement = JSON.parse(JSON.stringify(dActiveElement.value))
|
||||
changeStyleIconList()
|
||||
}
|
||||
|
||||
function changeValue() {
|
||||
if (state.tag) {
|
||||
state.tag = false
|
||||
return
|
||||
}
|
||||
if (dMoving.value) {
|
||||
return
|
||||
}
|
||||
// TODO 修改数值
|
||||
for (let key in state.innerElement) {
|
||||
if (state.ingoreKeys.indexOf(key) !== -1) {
|
||||
dActiveElement.value[key] = state.innerElement[key]
|
||||
} else if (key !== 'setting' && key !== 'record' && state.innerElement[key] !== dActiveElement.value[key]) {
|
||||
// const pushHistory = !['textEffects', 'transformData', 'fontClass'].includes(key)
|
||||
store.dispatch('updateWidgetData', {
|
||||
uuid: dActiveElement.value.uuid,
|
||||
key,
|
||||
value: state.innerElement[key],
|
||||
pushHistory: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function selectTextEffect({ key, value, style }: any) {
|
||||
const uuid = dActiveElement.value.uuid
|
||||
store.commit('setWidgetStyle', { uuid, key, value })
|
||||
if (style) {
|
||||
finish('color', style.color || '')
|
||||
}
|
||||
}
|
||||
|
||||
function loadFonts() {
|
||||
const localFonts = useFontStore.list
|
||||
const fontLists = { 当前页面: [], 中文: [], 英文: [] }
|
||||
for (const font of localFonts) {
|
||||
const { id, oid, value, url, alias, preview, lang } = font
|
||||
const item = { id, oid, value, url, alias, preview }
|
||||
lang === 'zh' ? fontLists['中文'].unshift(item) : fontLists['英文'].unshift(item)
|
||||
}
|
||||
fontLists['当前页面'] = usePageFontsFilter()
|
||||
state.fontClassList = fontLists
|
||||
}
|
||||
|
||||
function finish(key, value) {
|
||||
store.dispatch('updateWidgetData', {
|
||||
uuid: dActiveElement.value.uuid,
|
||||
key,
|
||||
value,
|
||||
pushHistory: false,
|
||||
})
|
||||
setTimeout(() => {
|
||||
key === 'fontClass' && (state.fontClassList['当前页面'] = usePageFontsFilter())
|
||||
}, 300)
|
||||
}
|
||||
|
||||
function layerAction(item) {
|
||||
store.dispatch('updateLayerIndex', {
|
||||
uuid: dActiveElement.value.uuid,
|
||||
value: item.value,
|
||||
})
|
||||
}
|
||||
|
||||
async function textStyleAction(item) {
|
||||
let value = item.key === 'textAlign' ? item.value : item.value[item.select ? 1 : 0]
|
||||
state.innerElement[item.key] = value
|
||||
// TODO: 对竖版文字的特殊处理
|
||||
item.key === 'writingMode' && relationChange()
|
||||
await nextTick()
|
||||
store.commit('updateRect')
|
||||
}
|
||||
|
||||
async function alignAction(item) {
|
||||
store.dispatch('updateAlign', {
|
||||
align: item.value,
|
||||
uuid: dActiveElement.value.uuid,
|
||||
})
|
||||
await nextTick()
|
||||
store.commit('updateRect')
|
||||
}
|
||||
|
||||
function changeStyleIconList() {
|
||||
for (let i = 0; i < state.styleIconList1.length; ++i) {
|
||||
let key = state.styleIconList1[i].key
|
||||
state.styleIconList1[i].select = false
|
||||
const [unchecked, checked] = state.styleIconList1[i].value
|
||||
switch (key) {
|
||||
case 'fontWeight':
|
||||
case 'textDecoration':
|
||||
case 'fontStyle':
|
||||
if (state.innerElement[key] !== unchecked && state.innerElement[key] == checked) {
|
||||
state.styleIconList1[i].select = !state.styleIconList1[i].select
|
||||
}
|
||||
break
|
||||
case 'writingMode':
|
||||
if (state.innerElement[key] !== unchecked) {
|
||||
state.styleIconList1[i].select = true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < state.styleIconList2.length; i++) {
|
||||
let key = state.styleIconList2[i].key
|
||||
state.styleIconList2[i].select = false
|
||||
if (key === 'textAlign' && state.innerElement[key] === state.styleIconList2[i].value) {
|
||||
state.styleIconList2[i].select = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function relationChange() {
|
||||
setTimeout(() => {
|
||||
if (dActiveElement.value.writingMode) {
|
||||
const w_record = dActiveElement.value.width
|
||||
state.innerElement.width = dActiveElement.value.height
|
||||
state.innerElement.height = w_record
|
||||
}
|
||||
}, 10)
|
||||
}
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
selectTextEffect,
|
||||
textStyleAction,
|
||||
finish,
|
||||
layerAction,
|
||||
alignAction
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['dActiveElement', 'dMoving']),
|
||||
isDraw() {
|
||||
return this.$route.name === 'Draw'
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
dActiveElement: {
|
||||
handler(newValue, oldValue) {
|
||||
this.change()
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
innerElement: {
|
||||
handler(newValue, oldValue) {
|
||||
this.changeValue()
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.timer = null
|
||||
this.change()
|
||||
setTimeout(() => {
|
||||
this.loadFonts()
|
||||
}, 100)
|
||||
},
|
||||
methods: {
|
||||
...mapActions(['updateWidgetData', 'updateAlign', 'updateLayerIndex', 'pushHistory']),
|
||||
testEffect({ key, value, style }) {
|
||||
console.log('选择回调')
|
||||
const uuid = this.dActiveElement.uuid
|
||||
this.$store.commit('setWidgetStyle', { uuid, key, value })
|
||||
if (style) {
|
||||
this.finish('color', style.color || '')
|
||||
}
|
||||
},
|
||||
loadFonts() {
|
||||
// if (!this.isDraw) {
|
||||
// useFontStore().init()
|
||||
const localFonts = useFontStore.list
|
||||
const fontLists = { 当前页面: [], 中文: [], 英文: [] }
|
||||
for (const font of localFonts) {
|
||||
const { id, oid, value, url, alias, preview, lang } = font
|
||||
const item = { id, oid, value, url, alias, preview }
|
||||
lang === 'zh' ? fontLists['中文'].unshift(item) : fontLists['英文'].unshift(item)
|
||||
}
|
||||
fontLists['当前页面'] = usePageFontsFilter()
|
||||
this.fontClassList = fontLists
|
||||
// }
|
||||
// const isDev = process.env.NODE_ENV === 'development'
|
||||
// if (!isDev) {
|
||||
// const { list } = await api.material.getFonts() // { name: 'SourceHanSansCN-Normal' }
|
||||
// this.fontClassList = this.fontClassList.concat(list)
|
||||
// }
|
||||
},
|
||||
change() {
|
||||
if (this.timer) {
|
||||
return
|
||||
}
|
||||
this.timer = true
|
||||
setTimeout(() => {
|
||||
this.timer = null
|
||||
}, 300)
|
||||
this.tag = true
|
||||
this.innerElement = JSON.parse(JSON.stringify(this.dActiveElement))
|
||||
this.changeStyleIconList()
|
||||
},
|
||||
changeValue() {
|
||||
if (this.tag) {
|
||||
this.tag = false
|
||||
return
|
||||
}
|
||||
if (this.dMoving) {
|
||||
return
|
||||
}
|
||||
// TODO 修改数值
|
||||
for (let key in this.innerElement) {
|
||||
if (this.ingoreKeys.indexOf(key) !== -1) {
|
||||
this.dActiveElement[key] = this.innerElement[key]
|
||||
} else if (key !== 'setting' && key !== 'record' && this.innerElement[key] !== this.dActiveElement[key]) {
|
||||
// console.log('???', key)
|
||||
// const pushHistory = !['textEffects', 'transformData', 'fontClass'].includes(key)
|
||||
this.updateWidgetData({
|
||||
uuid: this.dActiveElement.uuid,
|
||||
key,
|
||||
value: this.innerElement[key],
|
||||
pushHistory: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
finish(key, value) {
|
||||
this.updateWidgetData({
|
||||
uuid: this.dActiveElement.uuid,
|
||||
key: key,
|
||||
value: value,
|
||||
pushHistory: false,
|
||||
})
|
||||
setTimeout(() => {
|
||||
key === 'fontClass' && (this.fontClassList['当前页面'] = usePageFontsFilter())
|
||||
}, 300)
|
||||
},
|
||||
layerAction(item) {
|
||||
this.updateLayerIndex({
|
||||
uuid: this.dActiveElement.uuid,
|
||||
value: item.value,
|
||||
})
|
||||
},
|
||||
async textStyleAction(item) {
|
||||
let value = item.key === 'textAlign' ? item.value : item.value[item.select ? 1 : 0]
|
||||
this.innerElement[item.key] = value
|
||||
// TODO: 对竖版文字的特殊处理
|
||||
item.key === 'writingMode' && this.relationChange()
|
||||
await this.$nextTick()
|
||||
this.$store.commit('updateRect')
|
||||
},
|
||||
async alignAction(item) {
|
||||
this.updateAlign({
|
||||
align: item.value,
|
||||
uuid: this.dActiveElement.uuid,
|
||||
})
|
||||
await this.$nextTick()
|
||||
this.$store.commit('updateRect')
|
||||
},
|
||||
changeStyleIconList() {
|
||||
for (let i = 0; i < this.styleIconList1.length; ++i) {
|
||||
let key = this.styleIconList1[i].key
|
||||
this.styleIconList1[i].select = false
|
||||
switch (key) {
|
||||
case 'fontWeight':
|
||||
case 'fontStyle':
|
||||
if (this.innerElement[key] !== 'normal') {
|
||||
this.styleIconList1[i].select = true
|
||||
}
|
||||
break
|
||||
case 'textDecoration':
|
||||
if (this.innerElement[key] !== this.styleIconList1[i].value[0] && this.innerElement[key] == this.styleIconList1[i].value[1]) {
|
||||
this.styleIconList1[i].select = !this.styleIconList1[i].select
|
||||
}
|
||||
break
|
||||
case 'writingMode':
|
||||
if (this.innerElement[key] !== this.styleIconList1[i].value[0]) {
|
||||
this.styleIconList1[i].select = true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < this.styleIconList2.length; i++) {
|
||||
let key = this.styleIconList2[i].key
|
||||
this.styleIconList2[i].select = false
|
||||
if (key === 'textAlign' && this.innerElement[key] === this.styleIconList2[i].value) {
|
||||
this.styleIconList2[i].select = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
},
|
||||
relationChange() {
|
||||
setTimeout(() => {
|
||||
if (this.dActiveElement.writingMode) {
|
||||
const w_record = this.dActiveElement.width
|
||||
this.innerElement.width = this.dActiveElement.height
|
||||
this.innerElement.height = w_record
|
||||
}
|
||||
}, 10)
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
Loading…
x
Reference in New Issue
Block a user