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 Pause from '@/components/icons/Pause.vue'
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 Export from '@/components/icons/Export.vue'
import Delete from '@/components/icons/Delete.vue'
import IconButton from '@/components/common/IconButton.vue'
import Bottom from '@/components/icons/Bottom.vue'
import copy from 'copy-text-to-clipboard'
const themeVars = useThemeVars()
@ -95,15 +96,8 @@ const onStopMonitor = async () => {
}
const onCopyLog = async () => {
try {
const content = join(data.list, '\n')
const succ = await ClipboardSetText(content)
if (succ) {
copy(join(data.list, '\n'))
$message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
}
const onExportLog = () => {

View File

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

View File

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

View File

@ -5,13 +5,13 @@ import Copy from '@/components/icons/Copy.vue'
import Save from '@/components/icons/Save.vue'
import { useThemeVars } from 'naive-ui'
import { types as redisTypes } from '@/consts/support_redis_type.js'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { isEmpty, toLower } from 'lodash'
import useBrowserStore from 'stores/browser.js'
import { decodeRedisKey } from '@/utils/key_convert.js'
import ContentEditor from '@/components/content_value/ContentEditor.vue'
import { decodeTypes, formatTypes } from '@/consts/value_view_type.js'
import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const props = defineProps({
name: String,
@ -62,15 +62,8 @@ const showMemoryUsage = computed(() => {
* Copy value
*/
const onCopyValue = () => {
ClipboardSetText(displayValue.value)
.then((succ) => {
if (succ) {
copy(displayValue.value)
$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 Edit from '@/components/icons/Edit.vue'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const i18n = useI18n()
const themeVars = useThemeVars()
@ -180,14 +180,8 @@ const actionColumn = {
editing: false,
bindKey: `#${index + 1}`,
onCopy: async () => {
try {
const succ = await ClipboardSetText(row.v)
if (succ) {
copy(row.v)
$message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
},
onEdit: () => {
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 FormatSelector from '@/components/content_value/FormatSelector.vue'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const i18n = useI18n()
const themeVars = useThemeVars()
@ -177,14 +177,8 @@ const actionColumn = {
editing: false,
bindKey: `#${index + 1}`,
onCopy: async () => {
try {
const succ = await ClipboardSetText(row.v)
if (succ) {
copy(row.v)
$message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
},
onEdit: () => {
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 IconButton from '@/components/common/IconButton.vue'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const i18n = useI18n()
const themeVars = useThemeVars()
@ -108,14 +108,8 @@ const actionColumn = {
bindKey: row.id,
readonly: true,
onCopy: async () => {
try {
const succ = await ClipboardSetText(JSON.stringify(row.v))
if (succ) {
copy(JSON.stringify(row.v))
$message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
},
onDelete: async () => {
try {

View File

@ -6,13 +6,13 @@ import Save from '@/components/icons/Save.vue'
import { useThemeVars } from 'naive-ui'
import { formatTypes } from '@/consts/value_view_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 useBrowserStore from 'stores/browser.js'
import { decodeRedisKey } from '@/utils/key_convert.js'
import FormatSelector from '@/components/content_value/FormatSelector.vue'
import ContentEditor from '@/components/content_value/ContentEditor.vue'
import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const props = defineProps({
name: String,
@ -121,15 +121,8 @@ const onFormatChanged = async (decode = '', format = '') => {
* Copy value
*/
const onCopyValue = () => {
ClipboardSetText(displayValue.value)
.then((succ) => {
if (succ) {
copy(displayValue.value)
$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 Edit from '@/components/icons/Edit.vue'
import ContentSearchInput from '@/components/content_value/ContentSearchInput.vue'
import { ClipboardSetText } from 'wailsjs/runtime/runtime.js'
import { formatBytes } from '@/utils/byte_convert.js'
import copy from 'copy-text-to-clipboard'
const i18n = useI18n()
const themeVars = useThemeVars()
@ -224,14 +224,8 @@ const actionColumn = {
editing: false,
bindKey: row.v,
onCopy: async () => {
try {
const succ = await ClipboardSetText(row.v)
if (succ) {
copy(row.v)
$message.success(i18n.t('interface.copy_succ'))
}
} catch (e) {
$message.error(e.message)
}
},
onEdit: () => startEdit(index + 1, row.s, row.v),
onDelete: async () => {

View File

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