feat&fix: Text Settings

This commit is contained in:
ShawnPhang 2024-11-14 17:00:22 +08:00
parent e07a5cefe1
commit a203c41ea4
6 changed files with 27 additions and 13 deletions

View File

@ -2,8 +2,8 @@
* @Author: ShawnPhang * @Author: ShawnPhang
* @Date: 2021-08-02 18:27:27 * @Date: 2021-08-02 18:27:27
* @Description: * @Description:
* @LastEditors: ShawnPhang, Jeremy Yu <https://github.com/JeremyYu-cn> * @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2024-03-01 20:55:51 * @LastEditTime: 2024-11-14 16:41:19
*/ */
import { AlignListData } from "./AlignListData" import { AlignListData } from "./AlignListData"
@ -92,6 +92,13 @@ export const styleIconList2 = [
value: 'justify', value: 'justify',
select: false, select: false,
}, },
{
key: 'textAlignLast',
icon: 'icon-align-justify-text',
tip: '分散对齐',
value: 'justify',
select: false,
},
] as TStyleIconData2[] ] as TStyleIconData2[]
export const alignIconList = [ export const alignIconList = [

View File

@ -3,12 +3,12 @@
* @Date: 2021-07-29 18:31:27 * @Date: 2021-07-29 18:31:27
* @Description: * @Description:
* @LastEditors: ShawnPhang <https://m.palxp.cn> * @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2024-04-10 07:36:58 * @LastEditTime: 2024-11-14 16:48:06
--> -->
<template> <template>
<div class="icon-item-select"> <div class="icon-item-select">
<span v-if="label" class="label">{{ label }}</span> <span v-if="label" class="label">{{ label }}</span>
<ul class="list btn__bar flex"> <ul v-if="data" class="list btn__bar flex">
<el-tooltip v-for="(item, index) in data" :key="index" class="item" effect="dark" :content="item.tip" placement="top" :show-after="300" > <el-tooltip v-for="(item, index) in data" :key="index" class="item" effect="dark" :content="item.tip" placement="top" :show-after="300" >
<li :class="{ 'list-item': true, active: item.select }" @click="selectItem(item)"> <li :class="{ 'list-item': true, active: item.select }" @click="selectItem(item)">
<i :class="`${item.extraIcon ? 'icon' : 'iconfont'} ${item.icon}`"></i> <i :class="`${item.extraIcon ? 'icon' : 'iconfont'} ${item.icon}`"></i>
@ -52,6 +52,8 @@ function selectItem(item: TIconItemSelectData) {
item.select = !item.select item.select = !item.select
} }
emit('finish', item) emit('finish', item)
// text-align
item.key === 'textAlign' && (item.select = true)
} }
</script> </script>

View File

@ -17,6 +17,7 @@
fontSize: params.fontSize + 'px', fontSize: params.fontSize + 'px',
color: params.color, color: params.color,
textAlign: params.textAlign, textAlign: params.textAlign,
textAlignLast: params.textAlignLast,
fontWeight: params.fontWeight, fontWeight: params.fontWeight,
fontStyle: params.fontStyle, fontStyle: params.fontStyle,
textDecoration: params.textDecoration, textDecoration: params.textDecoration,
@ -188,7 +189,7 @@ function writeDone(e: Event) {
} }
function dblclickText(_: MouseEvent) { function dblclickText(_: MouseEvent) {
// store.commit('setShowMoveable', false) if (state.editable) return
state.editable = true state.editable = true
const el = editWrap.value || widget.value const el = editWrap.value || widget.value
setTimeout(() => { setTimeout(() => {

View File

@ -25,6 +25,7 @@ export type TwTextData = {
textDecoration: string textDecoration: string
color: string color: string
textAlign: StyleProperty.TextAlign textAlign: StyleProperty.TextAlign
textAlignLast: StyleProperty.TextAlign
text: string text: string
opacity: number opacity: number
backgroundColor: string backgroundColor: string

View File

@ -15,8 +15,8 @@
<value-select v-model="state.innerElement.fontSize" label="大小" suffix="px" :data="state.fontSizeList" @finish="(value) => finish('fontSize', value)" /> <value-select v-model="state.innerElement.fontSize" label="大小" suffix="px" :data="state.fontSizeList" @finish="(value) => finish('fontSize', value)" />
</div> </div>
<icon-item-select class="style-item" :data="styleIconList1" @finish="textStyleAction" /> <icon-item-select class="style-item" :data="state.styleIconList1" @finish="textStyleAction" />
<icon-item-select class="style-item" :data="styleIconList2" @finish="textStyleAction" /> <icon-item-select class="style-item" :data="state.styleIconList2" @finish="textStyleAction" />
<!-- <div style="flex-wrap: nowrap" class="line-layout style-item"> <!-- <div style="flex-wrap: nowrap" class="line-layout style-item">
<value-select v-model="innerElement.lineHeight" label="行距" suffix="倍" :data="lineHeightList" @finish="(value) => finish('lineHeight', value)" /> <value-select v-model="innerElement.lineHeight" label="行距" suffix="倍" :data="lineHeightList" @finish="(value) => finish('lineHeight', value)" />
@ -213,13 +213,16 @@ function layerAction(item: TIconItemSelectData) {
} }
async function textStyleAction(item: TIconItemSelectData) { async function textStyleAction(item: TIconItemSelectData) {
let value = item.key === 'textAlign' ? item.value : (item.value as number[])[item.select ? 1 : 0] const innerText = state.innerElement as Record<string, any>
;(state.innerElement as Record<string, any>)[item.key || ''] = value let value = ['textAlign', 'textAlignLast'].includes(item.key || '') ? item.value : (item.value as number[])[item.select ? 1 : 0]
// TODO: //
item.key === 'textAlignLast' && innerText[item.key] === value && (value = undefined)
//
item.key && (innerText[item.key] = value)
//
item.key === 'writingMode' && relationChange() item.key === 'writingMode' && relationChange()
await nextTick() await nextTick()
forceStore.setUpdateRect() forceStore.setUpdateRect()
// store.commit('updateRect')
} }
async function alignAction(item: TIconItemSelectData) { async function alignAction(item: TIconItemSelectData) {
@ -259,7 +262,7 @@ function changeStyleIconList() {
for (let i = 0; i < state.styleIconList2.length; i++) { for (let i = 0; i < state.styleIconList2.length; i++) {
let key = state.styleIconList2[i].key let key = state.styleIconList2[i].key
state.styleIconList2[i].select = false state.styleIconList2[i].select = false
if (key === 'textAlign' && state.innerElement[key] === state.styleIconList2[i].value) { if (['textAlign', 'textAlignLast'].includes(key || '') && state.innerElement[key] === state.styleIconList2[i].value) {
state.styleIconList2[i].select = true state.styleIconList2[i].select = true
continue continue
} }

View File

@ -1,6 +1,6 @@
namespace StyleProperty { namespace StyleProperty {
type TextAlign = "center" | "end" | "left" | "right" | "start"; type TextAlign = "center" | "end" | "left" | "right" | "start" | "justify";
type WritingMode = Globals | "horizontal-tb" | "sideways-lr" | "sideways-rl" | "vertical-lr" | "vertical-rl"; type WritingMode = Globals | "horizontal-tb" | "sideways-lr" | "sideways-rl" | "vertical-lr" | "vertical-rl";
} }