fix: copy text not work for non-ascii text (#246)

This commit is contained in:
Lykin 2024-06-19 14:39:37 +08:00
parent aa8c5495c1
commit bdfa31e4b6
10 changed files with 33 additions and 104 deletions

View File

@ -7,12 +7,13 @@ import useBrowserStore from 'stores/browser.js'
import Play from '@/components/icons/Play.vue' import Play from '@/components/icons/Play.vue'
import Pause from '@/components/icons/Pause.vue' import Pause from '@/components/icons/Pause.vue'
import { ExportLog, StartMonitor, StopMonitor } from 'wailsjs/go/services/monitorService.js' import { ExportLog, StartMonitor, StopMonitor } from 'wailsjs/go/services/monitorService.js'
import { ClipboardSetText, EventsOff, EventsOn } from 'wailsjs/runtime/runtime.js' import { EventsOff, EventsOn } from 'wailsjs/runtime/runtime.js'
import Copy from '@/components/icons/Copy.vue' import Copy from '@/components/icons/Copy.vue'
import Export from '@/components/icons/Export.vue' import Export from '@/components/icons/Export.vue'
import Delete from '@/components/icons/Delete.vue' import Delete from '@/components/icons/Delete.vue'
import IconButton from '@/components/common/IconButton.vue' import IconButton from '@/components/common/IconButton.vue'
import Bottom from '@/components/icons/Bottom.vue' import Bottom from '@/components/icons/Bottom.vue'
import copy from 'copy-text-to-clipboard'
const themeVars = useThemeVars() const themeVars = useThemeVars()
@ -95,15 +96,8 @@ const onStopMonitor = async () => {
} }
const onCopyLog = async () => { const onCopyLog = async () => {
try { copy(join(data.list, '\n'))
const content = join(data.list, '\n')
const succ = await ClipboardSetText(content)
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
} }
const onExportLog = () => { const onExportLog = () => {

View File

@ -9,12 +9,12 @@ import RedisTypeTag from '@/components/common/RedisTypeTag.vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import IconButton from '@/components/common/IconButton.vue' import IconButton from '@/components/common/IconButton.vue'
import Copy from '@/components/icons/Copy.vue' import Copy from '@/components/icons/Copy.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { computed, onMounted, onUnmounted, reactive, watch } from 'vue' import { computed, onMounted, onUnmounted, reactive, watch } from 'vue'
import { NIcon, useThemeVars } from 'naive-ui' import { NIcon, useThemeVars } from 'naive-ui'
import { timeout } from '@/utils/promise.js' import { timeout } from '@/utils/promise.js'
import AutoRefreshForm from '@/components/common/AutoRefreshForm.vue' import AutoRefreshForm from '@/components/common/AutoRefreshForm.vue'
import { toHumanReadable } from '@/utils/date.js' import { toHumanReadable } from '@/utils/date.js'
import copy from 'copy-text-to-clipboard'
const props = defineProps({ const props = defineProps({
server: String, server: String,
@ -139,15 +139,8 @@ const onToggleRefresh = (on) => {
} }
const onCopyKey = () => { const onCopyKey = () => {
ClipboardSetText(props.keyPath) copy(props.keyPath)
.then((succ) => {
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
})
.catch((e) => {
$message.error(e.message)
})
} }
const onTTL = () => { const onTTL = () => {

View File

@ -17,8 +17,8 @@ import Edit from '@/components/icons/Edit.vue'
import FormatSelector from '@/components/content_value/FormatSelector.vue' import FormatSelector from '@/components/content_value/FormatSelector.vue'
import { decodeRedisKey } from '@/utils/key_convert.js' import { decodeRedisKey } from '@/utils/key_convert.js'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue' import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { formatBytes } from '@/utils/byte_convert.js' import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const i18n = useI18n() const i18n = useI18n()
const themeVars = useThemeVars() const themeVars = useThemeVars()
@ -230,14 +230,8 @@ const actionColumn = {
} }
}, },
onCopy: async () => { onCopy: async () => {
try { copy(row.v)
const succ = await ClipboardSetText(row.v)
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
}, },
onEdit: () => startEdit(index + 1, row.k, row.v), onEdit: () => startEdit(index + 1, row.k, row.v),
onDelete: async () => { onDelete: async () => {

View File

@ -5,13 +5,13 @@ import Copy from '@/components/icons/Copy.vue'
import Save from '@/components/icons/Save.vue' import Save from '@/components/icons/Save.vue'
import { useThemeVars } from 'naive-ui' import { useThemeVars } from 'naive-ui'
import { types as redisTypes } from '@/consts/support_redis_type.js' import { types as redisTypes } from '@/consts/support_redis_type.js'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { isEmpty, toLower } from 'lodash' import { isEmpty, toLower } from 'lodash'
import useBrowserStore from 'stores/browser.js' import useBrowserStore from 'stores/browser.js'
import { decodeRedisKey } from '@/utils/key_convert.js' import { decodeRedisKey } from '@/utils/key_convert.js'
import ContentEditor from '@/components/content_value/ContentEditor.vue' import ContentEditor from '@/components/content_value/ContentEditor.vue'
import { decodeTypes, formatTypes } from '@/consts/value_view_type.js' import { decodeTypes, formatTypes } from '@/consts/value_view_type.js'
import { formatBytes } from '@/utils/byte_convert.js' import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const props = defineProps({ const props = defineProps({
name: String, name: String,
@ -62,15 +62,8 @@ const showMemoryUsage = computed(() => {
* Copy value * Copy value
*/ */
const onCopyValue = () => { const onCopyValue = () => {
ClipboardSetText(displayValue.value) copy(displayValue.value)
.then((succ) => {
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
})
.catch((e) => {
$message.error(e.message)
})
} }
/** /**

View File

@ -16,8 +16,8 @@ import ContentEntryEditor from '@/components/content_value/ContentEntryEditor.vu
import FormatSelector from '@/components/content_value/FormatSelector.vue' import FormatSelector from '@/components/content_value/FormatSelector.vue'
import Edit from '@/components/icons/Edit.vue' import Edit from '@/components/icons/Edit.vue'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue' import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { formatBytes } from '@/utils/byte_convert.js' import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const i18n = useI18n() const i18n = useI18n()
const themeVars = useThemeVars() const themeVars = useThemeVars()
@ -180,14 +180,8 @@ const actionColumn = {
editing: false, editing: false,
bindKey: `#${index + 1}`, bindKey: `#${index + 1}`,
onCopy: async () => { onCopy: async () => {
try { copy(row.v)
const succ = await ClipboardSetText(row.v)
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
}, },
onEdit: () => { onEdit: () => {
startEdit(index + 1, row.v) startEdit(index + 1, row.v)

View File

@ -16,8 +16,8 @@ import Edit from '@/components/icons/Edit.vue'
import ContentEntryEditor from '@/components/content_value/ContentEntryEditor.vue' import ContentEntryEditor from '@/components/content_value/ContentEntryEditor.vue'
import FormatSelector from '@/components/content_value/FormatSelector.vue' import FormatSelector from '@/components/content_value/FormatSelector.vue'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue' import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { formatBytes } from '@/utils/byte_convert.js' import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const i18n = useI18n() const i18n = useI18n()
const themeVars = useThemeVars() const themeVars = useThemeVars()
@ -177,14 +177,8 @@ const actionColumn = {
editing: false, editing: false,
bindKey: `#${index + 1}`, bindKey: `#${index + 1}`,
onCopy: async () => { onCopy: async () => {
try { copy(row.v)
const succ = await ClipboardSetText(row.v)
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
}, },
onEdit: () => { onEdit: () => {
startEdit(index + 1, row.v) startEdit(index + 1, row.v)

View File

@ -13,8 +13,8 @@ import LoadList from '@/components/icons/LoadList.vue'
import LoadAll from '@/components/icons/LoadAll.vue' import LoadAll from '@/components/icons/LoadAll.vue'
import IconButton from '@/components/common/IconButton.vue' import IconButton from '@/components/common/IconButton.vue'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue' import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { formatBytes } from '@/utils/byte_convert.js' import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const i18n = useI18n() const i18n = useI18n()
const themeVars = useThemeVars() const themeVars = useThemeVars()
@ -108,14 +108,8 @@ const actionColumn = {
bindKey: row.id, bindKey: row.id,
readonly: true, readonly: true,
onCopy: async () => { onCopy: async () => {
try { copy(JSON.stringify(row.v))
const succ = await ClipboardSetText(JSON.stringify(row.v))
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
}, },
onDelete: async () => { onDelete: async () => {
try { try {

View File

@ -6,13 +6,13 @@ import Save from '@/components/icons/Save.vue'
import { useThemeVars } from 'naive-ui' import { useThemeVars } from 'naive-ui'
import { formatTypes } from '@/consts/value_view_type.js' import { formatTypes } from '@/consts/value_view_type.js'
import { types as redisTypes } from '@/consts/support_redis_type.js' import { types as redisTypes } from '@/consts/support_redis_type.js'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { isEmpty, toLower } from 'lodash' import { isEmpty, toLower } from 'lodash'
import useBrowserStore from 'stores/browser.js' import useBrowserStore from 'stores/browser.js'
import { decodeRedisKey } from '@/utils/key_convert.js' import { decodeRedisKey } from '@/utils/key_convert.js'
import FormatSelector from '@/components/content_value/FormatSelector.vue' import FormatSelector from '@/components/content_value/FormatSelector.vue'
import ContentEditor from '@/components/content_value/ContentEditor.vue' import ContentEditor from '@/components/content_value/ContentEditor.vue'
import { formatBytes } from '@/utils/byte_convert.js' import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const props = defineProps({ const props = defineProps({
name: String, name: String,
@ -121,15 +121,8 @@ const onFormatChanged = async (decode = '', format = '') => {
* Copy value * Copy value
*/ */
const onCopyValue = () => { const onCopyValue = () => {
ClipboardSetText(displayValue.value) copy(displayValue.value)
.then((succ) => {
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
})
.catch((e) => {
$message.error(e.message)
})
} }
/** /**

View File

@ -16,8 +16,8 @@ import ContentEntryEditor from '@/components/content_value/ContentEntryEditor.vu
import FormatSelector from '@/components/content_value/FormatSelector.vue' import FormatSelector from '@/components/content_value/FormatSelector.vue'
import Edit from '@/components/icons/Edit.vue' import Edit from '@/components/icons/Edit.vue'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue' import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { formatBytes } from '@/utils/byte_convert.js' import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const i18n = useI18n() const i18n = useI18n()
const themeVars = useThemeVars() const themeVars = useThemeVars()
@ -224,14 +224,8 @@ const actionColumn = {
editing: false, editing: false,
bindKey: row.v, bindKey: row.v,
onCopy: async () => { onCopy: async () => {
try { copy(row.v)
const succ = await ClipboardSetText(row.v)
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
}, },
onEdit: () => startEdit(index + 1, row.s, row.v), onEdit: () => startEdit(index + 1, row.s, row.v),
onDelete: async () => { onDelete: async () => {

View File

@ -13,7 +13,6 @@ import Add from '@/components/icons/Add.vue'
import Layer from '@/components/icons/Layer.vue' import Layer from '@/components/icons/Layer.vue'
import Delete from '@/components/icons/Delete.vue' import Delete from '@/components/icons/Delete.vue'
import useDialogStore from 'stores/dialog.js' import useDialogStore from 'stores/dialog.js'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import useConnectionStore from 'stores/connections.js' import useConnectionStore from 'stores/connections.js'
import useTabStore from 'stores/tab.js' import useTabStore from 'stores/tab.js'
import IconButton from '@/components/common/IconButton.vue' import IconButton from '@/components/common/IconButton.vue'
@ -27,6 +26,7 @@ import usePreferencesStore from 'stores/preferences.js'
import { typesIconStyle } from '@/consts/support_redis_type.js' import { typesIconStyle } from '@/consts/support_redis_type.js'
import { nativeRedisKey } from '@/utils/key_convert.js' import { nativeRedisKey } from '@/utils/key_convert.js'
import { isMacOS } from '@/utils/platform.js' import { isMacOS } from '@/utils/platform.js'
import copy from 'copy-text-to-clipboard'
const props = defineProps({ const props = defineProps({
server: String, server: String,
@ -321,16 +321,9 @@ const handleKeyCopy = () => {
} }
if (node.type === ConnectionType.RedisValue) { if (node.type === ConnectionType.RedisValue) {
ClipboardSetText(nativeRedisKey(node.redisKeyCode || node.redisKey)) copy(nativeRedisKey(node.redisKeyCode || node.redisKey))
.then((succ) => {
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
} }
})
.catch((e) => {
$message.error(e.message)
})
}
} }
const onKeyShortcut = (e) => { const onKeyShortcut = (e) => {
@ -413,15 +406,8 @@ const handleSelectContextMenu = (action) => {
break break
case 'key_copy': case 'key_copy':
case 'value_copy': case 'value_copy':
ClipboardSetText(nativeRedisKey(redisKey)) copy(nativeRedisKey(redisKey))
.then((succ) => {
if (succ) {
$message.success(i18n.t('interface.copy_succ')) $message.success(i18n.t('interface.copy_succ'))
}
})
.catch((e) => {
$message.error(e.message)
})
break break
case 'db_loadall': case 'db_loadall':
if (node != null && !!!node.loading) { if (node != null && !!!node.loading) {