Skip to content

Commit 07d79e3

Browse files
YunaiVgitee-org
authored andcommitted
!29 Vue3 重构:基础设施 -> 文件管理功能 优化部分代码
Merge pull request !29 from xiaowuye/dev
2 parents d468124 + b6e3a58 commit 07d79e3

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

src/utils/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,12 @@ export const generateUUID = () => {
137137
return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
138138
})
139139
}
140+
141+
export const fileSizeFormatter = (row) => {
142+
const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
143+
const srcSize = parseFloat(row.size)
144+
const index = Math.floor(Math.log(srcSize) / Math.log(1024))
145+
const size = srcSize / Math.pow(1024, index)
146+
const sizeStr = size.toFixed(2) //保留的小数位数
147+
return sizeStr + ' ' + unitArr[index]
148+
}

src/views/infra/file/index.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
align="center"
5151
prop="size"
5252
width="120"
53-
:formatter="sizeFormat"
53+
:formatter="fileSizeFormatter"
5454
/>
5555
<el-table-column label="文件类型" align="center" prop="type" width="180px" />
5656
<el-table-column
@@ -86,6 +86,7 @@
8686
<file-upload-form ref="modalRef" @success="getList" />
8787
</template>
8888
<script setup lang="ts" name="Config">
89+
import { fileSizeFormatter } from '@/utils'
8990
import { dateFormatter } from '@/utils/formatTime'
9091
import * as FileApi from '@/api/infra/file'
9192
import FileUploadForm from './form.vue'
@@ -147,16 +148,6 @@ const handleDelete = async (id: number) => {
147148
} catch {}
148149
}
149150
150-
// TODO 写到 utils/index.ts 中
151-
const sizeFormat = (row) => {
152-
const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
153-
const srcSize = parseFloat(row.size)
154-
const index = Math.floor(Math.log(srcSize) / Math.log(1024))
155-
const size = srcSize / Math.pow(1024, index)
156-
const sizeStr = size.toFixed(2) //保留的小数位数
157-
return sizeStr + ' ' + unitArr[index]
158-
}
159-
160151
/** 初始化 **/
161152
onMounted(() => {
162153
getList()

src/views/infra/fileConfig/index.vue

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,28 +175,21 @@ const handleDelete = async (id: number) => {
175175
}
176176
177177
/** 主配置按钮操作 */
178-
const handleMaster = (id) => {
179-
// TODO 改成 await 的形式
180-
message
181-
.confirm('是否确认修改配置编号为"' + id + '"的数据项为主配置?')
182-
.then(function () {
183-
return FileConfigApi.updateFileConfigMaster(id)
184-
})
185-
.then(() => {
186-
getList()
187-
message.success(t('common.updateSuccess'))
188-
})
189-
.catch(() => {})
178+
const handleMaster = async (id) => {
179+
try {
180+
await message.confirm('是否确认修改配置编号为"' + id + '"的数据项为主配置?')
181+
await FileConfigApi.updateFileConfigMaster(id)
182+
message.success(t('common.updateSuccess'))
183+
await getList()
184+
} catch {}
190185
}
191186
192187
/** 测试按钮操作 */
193-
const handleTest = (id) => {
194-
// TODO 改成 await 的形式
195-
FileConfigApi.testFileConfig(id)
196-
.then((response) => {
197-
message.alert('测试通过,上传文件成功!访问地址:' + response)
198-
})
199-
.catch(() => {})
188+
const handleTest = async (id) => {
189+
try {
190+
const response = await FileConfigApi.testFileConfig(id)
191+
message.alert('测试通过,上传文件成功!访问地址:' + response)
192+
} catch {}
200193
}
201194
202195
/** 初始化 **/

0 commit comments

Comments
 (0)