feat: add dialog to manage data

This commit is contained in:
mio 2023-05-26 16:10:33 +08:00
parent 38cb320628
commit 839b8fd54a
7 changed files with 107 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{
"name": "star-rail-warp-export",
"version": "0.0.18",
"version": "0.1.0",
"main": "./dist/electron/main/main.js",
"author": "biuuu <https://github.com/biuuu>",
"license": "MIT",

View File

@ -42,6 +42,7 @@
"ui.setting.cnServer": "CN server",
"ui.setting.seaServer": "Global server",
"ui.setting.logTypeHint": "Choose which server generated logs to be used first when acquiring URL from game logs",
"ui.setting.dataManagerHint": "Unnecessary data can be deleted",
"ui.setting.autoUpdate": "Auto update",
"ui.setting.hideNovice": "Hide Starter Warp",
"ui.setting.proxyMode": "Proxy mode",
@ -57,6 +58,15 @@
"ui.urlDialog.placeholder": "Please enter the URL with authentication information",
"ui.common.cancel": "Cancel",
"ui.common.ok": "OK",
"ui.common.data": "Data",
"ui.common.dataManage": "Data Management",
"ui.common.updateTime": "Update Date",
"ui.common.status": "Status",
"ui.common.action": "Operation",
"ui.common.deleted": "Deleted",
"ui.common.normal": "Normal",
"ui.common.delete": "Delete",
"ui.common.restore": "Restore",
"log.save.failed": "Failed to save local data",
"log.file.notFound": "Unable to find game logs, please make sure you already opened warp history inside the game client",
"log.url.notFound": "Unable to find URL",

View File

@ -42,6 +42,7 @@
"ui.setting.cnServer": "国服",
"ui.setting.seaServer": "外服",
"ui.setting.logTypeHint": "使用游戏日志获取URL时优先选择哪种服务器生成的日志文件。",
"ui.setting.dataManagerHint": "可以删除不需要的数据。",
"ui.setting.autoUpdate": "自动更新",
"ui.setting.hideNovice": "隐藏新手跃迁",
"ui.setting.proxyMode": "代理模式",
@ -57,6 +58,15 @@
"ui.urlDialog.placeholder": "请输入带有身份认证信息的URL",
"ui.common.cancel": "取消",
"ui.common.ok": "确定",
"ui.common.data": "数据",
"ui.common.dataManage": "数据管理",
"ui.common.updateTime": "更新日期",
"ui.common.status": "状态",
"ui.common.action": "操作",
"ui.common.deleted": "已删除",
"ui.common.normal": "正常",
"ui.common.delete": "删除",
"ui.common.restore": "恢复",
"log.save.failed": "保存本地数据失败",
"log.file.notFound": "未找到游戏日志,确认是否已打开游戏抽卡记录",
"log.url.notFound": "未找到URL",

View File

@ -1,5 +1,5 @@
const { clipboard, ipcMain } = require('electron')
const { getUrl } = require('./getData')
const { getUrl, deleteData } = require('./getData')
ipcMain.handle('COPY_URL', async () => {
const url = await getUrl()
@ -8,4 +8,8 @@ ipcMain.handle('COPY_URL', async () => {
return true
}
return false
})
ipcMain.handle('DELETE_DATA', async (event, uid, action) => {
await deleteData(uid, action)
})

View File

@ -72,6 +72,14 @@ const readData = async () => {
}
}
const deleteData = async (uid, action) => {
const data = dataMap.get(uid)
if (data) {
data.deleted = action
await saveData(data)
}
}
const changeCurrent = async (uid) => {
config.current = uid
await config.save()
@ -513,3 +521,4 @@ exports.getData = () => {
}
exports.getUrl = getUrl
exports.deleteData = deleteData

View File

@ -12,9 +12,9 @@
</el-tooltip>
</div>
<div class="flex gap-2">
<el-select v-if="state.status !== 'loading' && state.dataMap && (state.dataMap.size > 1 || (state.dataMap.size === 1 && state.current === 0))" class="w-44" @change="changeCurrent" v-model="uidSelectText">
<el-select v-if="state.status !== 'loading' && dataMap && (dataMap.size > 1 || (dataMap.size === 1 && state.current === 0))" class="w-44" @change="changeCurrent" v-model="uidSelectText">
<el-option
v-for="item of state.dataMap"
v-for="item of dataMap"
:key="item[0]"
:label="maskUid(item[0])"
:value="item[0]">
@ -43,7 +43,7 @@
</div>
</div>
</div>
<Setting v-show="state.showSetting" :i18n="state.i18n" @changeLang="getI18nData()" @close="showSetting(false)"></Setting>
<Setting v-show="state.showSetting" :i18n="state.i18n" :gacha-data-info="dataInfo" @refreshData="readData()" @changeLang="getI18nData()" @close="showSetting(false)"></Setting>
<el-dialog :title="ui.urlDialog.title" v-model="state.showUrlDlg" width="90%" custom-class="max-w-md">
<p class="mb-4 text-gray-500">{{ui.urlDialog.hint}}</p>
@ -68,7 +68,6 @@
</div>
</template>
</el-dialog>
</div>
</template>
@ -98,6 +97,26 @@ const state = reactive({
config: {}
})
const dataMap = computed(() => {
const result = new Map()
for (let [uid, data] of state.dataMap) {
if (!data.deleted) {
result.set(uid, data)
}
}
return result
})
const dataInfo = computed(() => {
const result = []
for (let [uid, data] of state.dataMap) {
result.push({
uid, time: data.time, deleted: data.deleted
})
}
return result
})
const ui = computed(() => {
if (state.i18n) {
return state.i18n.ui
@ -154,7 +173,7 @@ const hint = computed(() => {
})
const detail = computed(() => {
const data = state.dataMap.get(state.current)
const data = dataMap.value.get(state.current)
if (data) {
return gachaDetail(data.result)
}

View File

@ -19,6 +19,10 @@
</el-radio-group>
<p class="text-gray-400 text-xs m-1.5">{{text.logTypeHint}}</p>
</el-form-item>
<el-form-item :label="common.data">
<el-button type="primary" plain @click="state.showDataDialog = true">{{common.dataManage}}</el-button>
<p class="text-gray-400 text-xs m-1.5">{{text.dataManagerHint}}</p>
</el-form-item>
<el-form-item :label="text.autoUpdate">
<el-switch
@change="saveSetting"
@ -51,21 +55,49 @@
<h3 class="text-lg my-4">{{about.title}}</h3>
<p class="text-gray-600 text-xs mt-1">{{about.license}}</p>
<p class="text-gray-600 text-xs mt-1 pb-6">Github: <a @click="openGithub" class="cursor-pointer text-blue-400">https://github.com/biuuu/star-rail-warp-export</a></p>
<el-dialog v-model="state.showDataDialog" :title="common.dataManage" width="90%">
<div class="">
<el-table :data="gachaDataInfo" border stripe>
<el-table-column property="uid" label="UID" width="128" />
<el-table-column property="time" :label="common.updateTime">
<template #default="scope">
{{ new Date(scope.row.time).toLocaleString() }}
</template>
</el-table-column>
<el-table-column property="deleted" :label="common.status" width="128">
<template #default="scope">
<el-tag type="info" size="small" v-if="scope.row.deleted">{{common.deleted}}</el-tag>
<el-tag type="success" size="small" v-else>{{common.normal}}</el-tag>
</template>
</el-table-column>
<el-table-column property="deleted" :label="common.action" width="128">
<template #default="scope">
<el-tooltip :content="scope.row.deleted ? common.restore : common.delete" placement="top">
<el-button :loading="state.dataActionLoading" size="small" icon="refresh" plain type="success" @click="deleteData(scope.row.uid, false)" v-if="scope.row.deleted"></el-button>
<el-button :loading="state.dataActionLoading" size="small" icon="delete" plain type="danger" @click="deleteData(scope.row.uid, true)" v-else></el-button>
</el-tooltip>
</template>
</el-table-column>
</el-table>
</div>
</el-dialog>
</div>
</template>
<script setup>
const { ipcRenderer, shell } = require('electron')
import { reactive, onMounted, computed } from 'vue'
const emit = defineEmits(['close', 'changeLang'])
const emit = defineEmits(['close', 'changeLang', 'refreshData'])
const props = defineProps({
i18n: Object
i18n: Object,
gachaDataInfo: Array
})
const data = reactive({
langMap: new Map()
langMap: new Map(),
})
const settingForm = reactive({
@ -77,6 +109,12 @@ const settingForm = reactive({
hideNovice: true
})
const state = reactive({
showDataDialog: false,
dataActionLoading: false
})
const common = computed(() => props.i18n.ui.common)
const text = computed(() => props.i18n.ui.setting)
const about = computed(() => props.i18n.ui.about)
@ -105,6 +143,13 @@ const exportUIGFJSON = () => {
ipcRenderer.invoke('EXPORT_UIGF_JSON')
}
const deleteData = async (uid, action) => {
state.dataActionLoading = true
await ipcRenderer.invoke('DELETE_DATA', uid, action)
state.dataActionLoading = false
emit('refreshData')
}
onMounted(async () => {
data.langMap = await ipcRenderer.invoke('LANG_MAP')
const config = await ipcRenderer.invoke('GET_CONFIG')