fix: 修复示例无法复制配置的问题 (#639)

This commit is contained in:
悠静萝莉 2023-11-16 03:48:02 +08:00 committed by GitHub
parent 81220e78c2
commit badc73e82b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,12 +65,15 @@
</t-form> </t-form>
<div class="setting-info"> <div class="setting-info">
<p>请复制后手动修改配置文件: /src/config/style.ts</p> <p>请复制后手动修改配置文件: /src/config/style.ts</p>
<t-button theme="primary" variant="text" @click="handleCopy"> 复制配置项 </t-button>
</div> </div>
</div> </div>
</t-drawer> </t-drawer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { MessagePlugin } from 'tdesign-vue-next';
import { computed, onMounted, ref, watchEffect } from 'vue'; import { computed, onMounted, ref, watchEffect } from 'vue';
import useClipboard from 'vue-clipboard3';
import LayoutMixIcon from '@/assets/assets-layout-mix.svg'; import LayoutMixIcon from '@/assets/assets-layout-mix.svg';
import LayoutSideIcon from '@/assets/assets-layout-side.svg'; import LayoutSideIcon from '@/assets/assets-layout-side.svg';
@ -142,6 +145,20 @@ const handleCloseDrawer = () => {
}); });
}; };
const handleCopy = () => {
const text = JSON.stringify(formData.value, null, 4);
const { toClipboard } = useClipboard();
toClipboard(text)
.then(() => {
MessagePlugin.closeAll();
MessagePlugin.success('复制成功');
})
.catch(() => {
MessagePlugin.closeAll();
MessagePlugin.error('复制失败');
});
};
watchEffect(() => { watchEffect(() => {
if (formData.value.brandTheme) settingStore.updateConfig(formData.value); if (formData.value.brandTheme) settingStore.updateConfig(formData.value);
}); });