Merge branch 'main' into feat-upgrade-vue3

This commit is contained in:
IchliebedichZhu 2024-03-02 11:37:30 +00:00
commit d21ce04738
8 changed files with 315 additions and 297 deletions

View File

@ -67,7 +67,15 @@ npm run serve
- [qr-code-styling](https://qr-code-styling.com/): 风格化二维码 - [qr-code-styling](https://qr-code-styling.com/): 风格化二维码
- [rembg](https://github.com/danielgatis/rembg): 图片抠图,使用 u2net 预训练模型 - [rembg](https://github.com/danielgatis/rembg): 图片抠图,使用 u2net 预训练模型
或许你在工作中有类似的需求,或许你对开发编辑器感兴趣,也希望这个项目能给到你一些微薄帮助! ### 友情赞助商
[![](https://xp.palxp.cn/images/2024-3-1-1709306907030.png)](https://dooring.vip/)
### 交流群
| 作者微信:备注加群 | 公众号 |
| --- | --- |
| ![](https://xp.palxp.cn/images/2024-3-1-1709306328344.png) | ![](https://xp.palxp.cn/images/2024-3-1-1709306365949.png) |
### `Star` ### `Star`

View File

@ -3,7 +3,7 @@
* @Date: 2021-08-27 15:16:07 * @Date: 2021-08-27 15:16:07
* @Description: 素材列表主要用于文字组合列表 * @Description: 素材列表主要用于文字组合列表
* @LastEditors: ShawnPhang <https://m.palxp.cn> * @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2024-01-11 17:59:57 * @LastEditTime: 2024-02-29 16:54:28
--> -->
<template> <template>
<div class="wrap"> <div class="wrap">
@ -241,14 +241,14 @@ export default defineComponent({
background: #f8fafc; background: #f8fafc;
} }
&__img { &__img {
cursor: pointer; cursor: grab;
width: 142px; width: 142px;
height: 142px; height: 142px;
padding: 4px; padding: 4px;
border-radius: 4px; border-radius: 4px;
} }
&__img-thumb { &__img-thumb {
cursor: pointer; cursor: grab;
width: 90px; width: 90px;
height: 90px; height: 90px;
background: #f8fafc; background: #f8fafc;

View File

@ -3,7 +3,7 @@
* @Date: 2021-08-27 15:16:07 * @Date: 2021-08-27 15:16:07
* @Description: 素材列表 * @Description: 素材列表
* @LastEditors: ShawnPhang <https://m.palxp.cn> * @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2023-11-24 11:14:28 * @LastEditTime: 2024-02-29 16:49:59
--> -->
<template> <template>
<div class="wrap"> <div class="wrap">
@ -217,14 +217,14 @@ export default defineComponent({
background: #f8fafc; background: #f8fafc;
} }
&__img { &__img {
cursor: pointer; cursor: grab;
width: 142px; width: 142px;
height: 142px; height: 142px;
padding: 4px; padding: 4px;
border-radius: 4px; border-radius: 4px;
} }
&__img-thumb { &__img-thumb {
cursor: pointer; cursor: grab;
width: 90px; width: 90px;
height: 90px; height: 90px;
background: #f8fafc; background: #f8fafc;

View File

@ -70,7 +70,7 @@ export default {
{ {
text: '+ 添加文字', text: '+ 添加文字',
fontSize: 60, fontSize: 60,
fontWeight: 'bold', fontWeight: 'normal',
}, },
// { // {
// text: '+ ', // text: '+ ',
@ -97,8 +97,7 @@ export default {
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
// Color variables (appears count calculates by raw css) // @color0: #3b74f1;
@color0: #3b74f1; // Appears 2 times
#text-list-wrap { #text-list-wrap {
display: flex; display: flex;

View File

@ -3,7 +3,7 @@
* @Date: 2022-02-23 15:48:52 * @Date: 2022-02-23 15:48:52
* @Description: 图片列表组件 Bookshelf Layout * @Description: 图片列表组件 Bookshelf Layout
* @LastEditors: ShawnPhang <https://m.palxp.cn> * @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2023-12-11 11:12:04 * @LastEditTime: 2024-02-29 16:52:37
--> -->
<template> <template>
<ul ref="listRef" class="img-list-wrap" :style="{ paddingBottom: isShort ? '15px' : '200px' }" @scroll="scrollEvent($event)"> <ul ref="listRef" class="img-list-wrap" :style="{ paddingBottom: isShort ? '15px' : '200px' }" @scroll="scrollEvent($event)">
@ -207,7 +207,7 @@ export default defineComponent({
&__img { &__img {
// background: #f1f2f4; // background: #f1f2f4;
display: inline-block; display: inline-block;
cursor: pointer; cursor: grab;
// margin: 0 6px 2px 0; // margin: 0 6px 2px 0;
margin-bottom: 3px; margin-bottom: 3px;
border-radius: 2px; border-radius: 2px;

View File

@ -57,7 +57,9 @@ export default defineComponent({
onMounted(() => { onMounted(() => {
if (props.modelValue) { if (props.modelValue) {
state.innerColor = props.modelValue + (props.modelValue.length === 7 ? 'ff' : '') let fixColor = props.modelValue + (props.modelValue.length === 7 ? 'ff' : '')
// @palxp/color-picker16
state.innerColor = fixColor.toLocaleUpperCase()
} }
}) })
const dropColor = async (e: any) => { const dropColor = async (e: any) => {

View File

@ -49,15 +49,17 @@
</div> </div>
</template> </template>
<script> <script lang="ts">
// //
const NAME = 'w-text' 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 { fontWithDraw } from '@/utils/widgets/loadFontRule'
import getGradientOrImg from './getGradientOrImg.ts' import getGradientOrImg from './getGradientOrImg.ts'
export default { export default defineComponent({
name: NAME, name: NAME,
setting: { setting: {
name: '文本', name: '文本',
@ -97,116 +99,122 @@ export default {
}, },
}, },
props: ['params', 'parent'], props: ['params', 'parent'],
data() { setup(props) {
return { const store = useStore()
const route = useRoute()
const state = reactive({
loading: false, loading: false,
editable: false, editable: false,
loadFontDone: false, loadFontDone: false,
} })
}, const widget = ref(null)
computed: { const editWrap = ref(null)
...mapGetters(['dActiveElement']),
isDraw() { const dActiveElement = computed(() => store.getters.dActiveElement)
return this.$route.name === 'Draw' && fontWithDraw const isDraw = computed(() => route.name === 'Draw' && fontWithDraw)
},
}, onUpdated(() => {
watch: { updateRecord()
params: { })
async handler(nval) {
this.updateText() onMounted(() => {
if (this.loading) { 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 return
} }
let font = nval.fontClass let font = nval.fontClass
const isDone = font.value === this.loadFontDone const isDone = font.value === state.loadFontDone
if (font.url && !isDone) { if (font.url && !isDone) {
if (font.id && this.isDraw) { if (font.id && isDraw.value) {
// url // url
// demobug // demobug
this.loading = false state.loading = false
return return
} }
this.loading = !this.isDraw state.loading = !isDraw.value
const loadFont = new window.FontFace(font.value, `url(${font.url})`) const loadFont = new window.FontFace(font.value, `url(${font.url})`)
await loadFont.load() await loadFont.load()
document.fonts.add(loadFont) document.fonts.add(loadFont)
this.loadFontDone = font.value state.loadFontDone = font.value
this.loading = false state.loading = false
} else { } else {
this.loading = false state.loading = false
} }
}, },
immediate: true, { immediate: true, deep: true },
deep: true, )
},
editable(value) { watch(
this.updateWidgetData({ () => state.editable,
uuid: this.params.uuid, (value) => {
key: 'editable', store.dispatch('updateWidgetData', {
value, uuid: props.params.uuid,
pushHistory: false, key: 'editable',
}) value,
}, pushHistory: false,
}, })
updated() { },
this.updateRecord() )
},
async mounted() { function updateRecord() {
this.updateRecord() if (dActiveElement.value.uuid === props.params.uuid) {
// await this.$nextTick() let record = dActiveElement.value.record
this.params.transform && (this.$refs.widget.style.transform = this.params.transform) record.width = widget.value.offsetWidth
this.params.rotate && (this.$refs.widget.style.transform += `translate(0px, 0px) rotate(${this.params.rotate}) scale(1, 1)`) record.height = widget.value.offsetHeight
// this.$store.commit('updateRect') record.minWidth = props.params.fontSize
}, record.minHeight = props.params.fontSize * props.params.lineHeight
methods: { writingText()
...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()
} }
}, }
updateText(e) {
const value = e ? e.target.innerHTML : this.params.text.replace(/\n/g, '<br/>') function updateText(e) {
// const value = (e ? e.target.innerText : this.params.text).replace(/<br\/>/g, '\r\n').replace(/&nbsp;/g, ' ') const value = e ? e.target.innerHTML : props.params.text.replace(/\n/g, '<br/>')
if (value !== this.params.text) { // const value = (e ? e.target.innerText : props.params.text).replace(/<br\/>/g, '\r\n').replace(/&nbsp;/g, ' ')
this.updateWidgetData({ if (value !== props.params.text) {
uuid: this.params.uuid, store.dispatch('updateWidgetData', {
uuid: props.params.uuid,
key: 'text', key: 'text',
value, value,
pushHistory: false, pushHistory: false,
}) })
} }
}, }
writingText(e) {
// this.updateText(e) function writingText(e) {
// updateText(e)
// TODO: // TODO:
const el = this.$refs.editWrap || this.$refs.widget const el = editWrap.value || widget.value
this.updateWidgetData({ store.dispatch('updateWidgetData', {
uuid: this.params.uuid, uuid: props.params.uuid,
key: 'height', key: 'height',
value: el.offsetHeight, value: el.offsetHeight,
pushHistory: false, pushHistory: false,
}) })
this.$store.commit('updateRect') store.commit('updateRect')
}, }
writeDone(e) {
this.editable = false function writeDone(e) {
state.editable = false
setTimeout(() => { setTimeout(() => {
this.pushHistory('文字修改') store.dispatch('pushHistory', '文字修改')
}, 100) }, 100)
this.updateText(e) updateText(e)
}, }
dblclickText(e) {
// this.$store.commit('setShowMoveable', false) function dblclickText(e) {
this.editable = true // store.commit('setShowMoveable', false)
const el = this.$refs.editWrap || this.$refs.widget state.editable = true
const el = editWrap.value || widget.value
setTimeout(() => { setTimeout(() => {
el.focus() el.focus()
if (document.selection) { if (document.selection) {
@ -220,9 +228,21 @@ export default {
window.getSelection().addRange(range) window.getSelection().addRange(range)
} }
}, 100) }, 100)
}, }
return {
...toRefs(state),
getGradientOrImg,
updateRecord,
writingText,
updateText,
writeDone,
dblclickText,
widget,
editWrap,
}
}, },
} })
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@ -247,13 +267,4 @@ export default {
width: 100%; width: 100%;
height: 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> </style>

View File

@ -34,7 +34,7 @@
<!-- <color-select v-model="innerElement.backgroundColor" label="背景颜色" @finish="(value) => finish('backgroundColor', value)" /> --> <!-- <color-select v-model="innerElement.backgroundColor" label="背景颜色" @finish="(value) => finish('backgroundColor', value)" /> -->
</div> </div>
<div class="line-layout style-item"> <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> </div>
<icon-item-select class="style-item" :data="layerIconList" @finish="layerAction" /> <icon-item-select class="style-item" :data="layerIconList" @finish="layerAction" />
<icon-item-select class="style-item" :data="alignIconList" @finish="alignAction" /> <icon-item-select class="style-item" :data="alignIconList" @finish="alignAction" />
@ -48,13 +48,13 @@
</div> </div>
</template> </template>
<script> <script lang="ts">
// //
const NAME = 'w-text-style' const NAME = 'w-text-style'
// import api from '@/api' import { defineComponent, reactive, toRefs, computed, watch, nextTick, onMounted } from 'vue'
// import _config from '@/config' import { useStore } from 'vuex'
import { mapGetters, mapActions } from 'vuex' import { useRoute } from 'vue-router'
import { styleIconList1, styleIconList2, alignIconList } from '../../../../assets/data/TextIconsData' import { styleIconList1, styleIconList2, alignIconList } from '@/assets/data/TextIconsData'
import layerIconList from '@/assets/data/LayerIconList' import layerIconList from '@/assets/data/LayerIconList'
import numberInput from '../../settings/numberInput.vue' import numberInput from '../../settings/numberInput.vue'
import numberSlider from '../../settings/numberSlider.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 { useFontStore } from '@/common/methods/fonts'
import usePageFontsFilter from './pageFontsFilter.ts' import usePageFontsFilter from './pageFontsFilter.ts'
export default { export default defineComponent({
name: NAME, name: NAME,
components: { numberInput, colorSelect, iconItemSelect, textInputArea, valueSelect, effectWrap, numberSlider }, components: { numberInput, colorSelect, iconItemSelect, textInputArea, valueSelect, effectWrap, numberSlider },
data() { setup() {
return { const store = useStore()
activeNames: [], const route = useRoute()
innerElement: {}, const state = reactive({
tag: false, activeNames: [],
ingoreKeys: ['left', 'top', 'name', 'width', 'height', 'text', 'color', 'backgroundColor'], innerElement: {},
fontSizeList: [12, 14, 24, 26, 28, 30, 36, 48, 60, 72, 96, 108, 120, 140, 180, 200, 250, 300, 400, 500], tag: false,
fontClassList: [], // ingoreKeys: ['left', 'top', 'name', 'width', 'height', 'text', 'color', 'backgroundColor'],
lineHeightList: [1, 1.5, 2], fontSizeList: [12, 14, 24, 26, 28, 30, 36, 48, 60, 72, 96, 108, 120, 140, 180, 200, 250, 300, 400, 500],
letterSpacingList: [0, 10, 25, 50, 75, 100, 200], fontClassList: [], //
layerIconList, lineHeightList: [1, 1.5, 2],
styleIconList1, letterSpacingList: [0, 10, 25, 50, 75, 100, 200],
styleIconList2, layerIconList,
alignIconList, 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> </script>
<style lang="less" scoped> <style lang="less" scoped>