广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-02 80ff784bf60637cd348ae665fc907f7b1e527dd8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import Clipboard from 'clipboard';
import { useThemeStore } from '@/store/modules/theme';
import { $t } from '@/locales';
 
defineOptions({
  name: 'ConfigOperation'
});
 
const themeStore = useThemeStore();
 
const domRef = ref<HTMLElement | null>(null);
 
function initClipboard() {
  if (!domRef.value) return;
 
  const clipboard = new Clipboard(domRef.value);
 
  clipboard.on('success', () => {
    window.$message?.success($t('theme.configOperation.copySuccessMsg'));
  });
}
 
function getClipboardText() {
  const reg = /"\w+":/g;
 
  const json = themeStore.settingsJson;
 
  return json.replace(reg, match => match.replace(/"/g, ''));
}
 
function handleReset() {
  themeStore.resetStore();
 
  setTimeout(() => {
    window.$message?.success($t('theme.configOperation.resetSuccessMsg'));
  }, 50);
}
 
const dataClipboardText = computed(() => getClipboardText());
 
onMounted(() => {
  initClipboard();
});
</script>
 
<template>
  <div class="w-full flex justify-between">
    <textarea id="themeConfigCopyTarget" v-model="dataClipboardText" class="absolute opacity-0 -z-1" />
    <NButton type="error" ghost @click="handleReset">{{ $t('theme.configOperation.resetConfig') }}</NButton>
    <div ref="domRef" data-clipboard-target="#themeConfigCopyTarget">
      <NButton type="primary">{{ $t('theme.configOperation.copyConfig') }}</NButton>
    </div>
  </div>
</template>
 
<style scoped></style>