Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wudg/AmazeCard
Browse files Browse the repository at this point in the history
  • Loading branch information
wudg committed Jun 23, 2024
2 parents 4686660 + 13357ac commit d64f6ec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
40 changes: 30 additions & 10 deletions src/pages/index/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="layout-wrapper" ref="container">
<div class="left">
<div class="top" ref="topRef">
<div class="content-box" ref="contentToCapture" :style="[{width: wS}, {height: hS} , config.margin]" :class="config.backgroundColor">
<div class="content-box" ref="contentToCapture" :style="[{width: wS}, hS, config.margin]" :class="config.backgroundColor">
<div class="content quillEditor ql-container ql-snow" :style="[config.theme, config.radius, config.padding, config.fontSize]">
<div :style="config.color" :class="[config.fontFamily]" class="ql-editor">
<div v-html="config.content"></div>
Expand Down Expand Up @@ -49,7 +49,7 @@

<div class="textarea-content">

<richText v-model="config.content" />
<richText v-model="config.content" @input="richTextInput"/>

<!-- <textarea class="textarea__inner" ref="textarea" v-model="config.content" :placeholder="$t('contnet_text_title')"></textarea> -->
</div>
Expand Down Expand Up @@ -307,7 +307,7 @@
</template>

<script setup>
import { onBeforeMount, onMounted, ref, computed } from 'vue';
import { onBeforeMount, onMounted, ref, computed, watch } from 'vue';
import { get, post } from '../../api/http';
import interfaces from '../../api/interfaces';
import { useSetUser, useAuth } from '../../util/composables';
Expand Down Expand Up @@ -367,12 +367,16 @@ const isWeixinBrowser = () => {
// 动态计算div的宽高来按照一定的比例自适应
const computeWH = function(w, h, box_width, box_height) {
const scale = w / h; // 比例
if (scale <= box_width / box_height) {
if (scale <= box_width / box_height) {
if((box_height * scale) > box_width) {
return;
}
wS.value = `${box_height * scale}px`; // 计算宽
hS.value = `${box_height}px`; // 计算高
} else {
hS.value = `min-height: ${box_height}px`; // 计算高
} else {
wS.value = `${box_width}px`;
hS.value = `${box_width / scale}px`;
hS.value = `height: ${box_width / scale}px`;
}
};
Expand Down Expand Up @@ -426,7 +430,7 @@ async function captureElement() {
const canvas = await html2canvas(contentToCapture.value, {
useCORS: true, // 如果有跨域资源,设置为true
backgroundColor: '#fff', // 设置背景颜色,默认为白色
scale: 5
scale: 10
// 可以根据需要添加更多配置选项
});
// 将canvas转为图片URL
Expand All @@ -452,7 +456,7 @@ const generateImg = async () => {
const canvas = await html2canvas(contentToCapture.value, {
useCORS: true, // 如果有跨域资源,设置为true
backgroundColor: '#fff', // 设置背景颜色,默认为白色
scale: 5
scale: 10
// 可以根据需要添加更多配置选项
});
// 将canvas转为图片URL
Expand All @@ -477,7 +481,7 @@ async function copyImg() {
const canvas = await html2canvas(contentToCapture.value, {
useCORS: true, // 如果有跨域资源,设置为true
backgroundColor: '#fff', // 设置背景颜色,默认为白色
scale: 5
scale: 10
// 可以根据需要添加更多配置选项
});
// 将canvas转为图片URL
Expand Down Expand Up @@ -640,7 +644,23 @@ onMounted(async () => {
integrationTheme();
computeWH(sizeList.value[sizeValue.value].w, sizeList.value[sizeValue.value].h, topRef.value.clientWidth, topRef.value.clientHeight );
});
const richTextInput = () => {
if (topRef.value) {
console.log(topRef.value.clientWidth);
// 根据元素的尺寸变化更新状态或执行其他逻辑
setTimeout(() => {
if(sizeValue.value < 0){
computeWH(customW.value, customH.value, topRef.value.clientWidth, topRef.value.clientHeight );
return;
}
computeWH(sizeList.value[sizeValue.value].w, sizeList.value[sizeValue.value].h, topRef.value.clientWidth, topRef.value.clientHeight );
}, 300);
}
};
</script>

<style lang="less">
Expand Down
14 changes: 5 additions & 9 deletions src/pages/index/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
position: relative;
background: var(--current-block-background-color);
width: 100%; /* 固定宽度 */
height: 500px; /* 父元素高度 */
min-height: 500px; /* 父元素高度 */
border-radius: 16px;
transition: all .1s;
display: flex;
Expand Down Expand Up @@ -52,12 +52,7 @@
position: relative;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
justify-content: center;
}

.content {
Expand All @@ -68,7 +63,8 @@
white-space: pre-wrap;
word-break: break-word;
border: 1px solid hsla(0, 0%, 100%, .0);

max-height: 95%;
overflow: hidden;
}

.options-title {
Expand Down Expand Up @@ -383,7 +379,7 @@
margin: 0 5px;
height: 28px;
font-size: 28px;
line-height: 38px;
line-height: 28px;
}
}
}

0 comments on commit d64f6ec

Please sign in to comment.