Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
闫辉
VueJS_644213
提交
70f9dcef
V
VueJS_644213
项目概览
闫辉
/
VueJS_644213
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VueJS_644213
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
70f9dcef
编写于
9月 30, 2024
作者:
S
superyan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Mon Sep 30 14:36:00 CST 2024 inscode
上级
79c5bd79
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
234 addition
and
47 deletion
+234
-47
index.html
index.html
+7
-10
package.json
package.json
+3
-0
public/index.html
public/index.html
+10
-0
src/App.vue
src/App.vue
+208
-34
src/main.js
src/main.js
+6
-3
未找到文件。
index.html
浏览文件 @
70f9dcef
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
/>
<link
rel=
"icon"
href=
"/favicon.ico"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
/>
<title>
Vite App
</title>
</head>
<body>
<div
id=
"app"
></div>
<script
type=
"module"
src=
"/src/main.js"
></script>
</body>
<head>
<meta
charset=
"UTF-8"
/>
<title>
SuperScaler
</title>
</head>
<body>
<div
id=
"app"
></div>
</body>
</html>
package.json
浏览文件 @
70f9dcef
...
...
@@ -7,6 +7,9 @@
"preview"
:
"vite preview --port 4173"
},
"dependencies"
:
{
"
aonweb
"
:
"
^2.0.3
"
,
"
axios
"
:
"
^1.7.7
"
,
"
element-plus
"
:
"
^2.8.4
"
,
"
guess
"
:
"
^1.0.2
"
,
"
vue
"
:
"
^3.2.37
"
},
...
...
public/index.html
0 → 100644
浏览文件 @
70f9dcef
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
/>
<title>
SuperScaler
</title>
</head>
<body>
<div
id=
"app"
></div>
</body>
</html>
src/App.vue
浏览文件 @
70f9dcef
<
script
setup
>
import
HelloWorld
from
'
./components/HelloWorld.vue
'
import
TheWelcome
from
'
./components/TheWelcome.vue
'
<!-- src/App.vue -->
<
template
>
<el-container
class=
"app-container"
>
<el-header>
<h1>
SuperScaler
</h1>
</el-header>
<el-main>
<el-upload
class=
"upload-demo"
action=
""
:before-upload=
"beforeUpload"
:http-request=
"httpRequest"
:on-exceed=
"onOversize"
:show-file-list=
"false"
accept=
"image/*"
>
<el-button
type=
"primary"
>
点击上传图片
</el-button>
</el-upload>
<el-row
justify=
"center"
v-if=
"loading"
>
<el-col
:span=
"24"
class=
"loading-col"
>
<el-progress
:percentage=
"progress"
type=
"circle"
></el-progress>
<p>
正在处理,请稍候...
</p>
</el-col>
</el-row>
<el-row
justify=
"center"
v-if=
"error"
>
<el-col
:span=
"24"
class=
"error-col"
>
<el-alert
:title=
"error"
type=
"error"
show-icon
></el-alert>
</el-col>
</el-row>
<el-row
justify=
"center"
v-if=
"resultImage"
>
<el-col
:span=
"24"
class=
"result-col"
>
<h2>
结果:
</h2>
<img
:src=
"resultImage"
alt=
"Upscaled Image"
class=
"result-image"
/>
<el-button
type=
"primary"
@
click=
"downloadImage"
>
下载图片
</el-button>
</el-col>
</el-row>
</el-main>
</el-container>
</
template
>
<
script
>
import
{
AI
,
User
}
from
'
aonweb
'
import
axios
from
'
axios
'
export
default
{
name
:
'
App
'
,
data
()
{
return
{
imageFile
:
null
,
resultImage
:
''
,
loading
:
false
,
error
:
''
,
app_key
:
'
YOUR_APP_KEY
'
,
// 请替换为您的 app_key
progress
:
0
,
}
},
methods
:
{
beforeUpload
(
file
)
{
const
isLt30M
=
file
.
size
/
1024
/
1024
<
30
if
(
!
isLt30M
)
{
this
.
$message
.
error
(
'
文件大小不能超过30MB!
'
)
return
false
}
this
.
imageFile
=
file
this
.
Generate
()
return
false
},
httpRequest
()
{
// 由于我们在 beforeUpload 中处理了上传,这里留空
},
onOversize
(
file
)
{
this
.
$message
.
error
(
'
文件大小不能超过30MB!
'
)
},
async
Generate
()
{
if
(
!
this
.
imageFile
)
{
this
.
error
=
'
请选择一张图像文件。
'
return
}
this
.
loading
=
true
this
.
error
=
''
this
.
progress
=
0
const
options
=
{
app_key
:
this
.
app_key
,
is_async
:
true
,
}
const
aonet
=
new
AI
(
options
)
const
user_
=
new
User
()
let
user
=
await
user_
.
islogin
()
if
(
!
user
)
{
user
=
await
user_
.
login
()
}
// 上传图像并获取 URL
let
imageUploadUrl
=
''
try
{
const
formData
=
new
FormData
()
formData
.
append
(
'
file
'
,
this
.
imageFile
)
const
uploadResponse
=
await
axios
.
post
(
'
https://tmp-file.aigic.ai/api/v1/upload?expires=1800&type=image/png
'
,
formData
,
{
headers
:
{
'
Content-Type
'
:
'
multipart/form-data
'
,
},
}
)
const
uploadResult
=
uploadResponse
.
data
if
(
uploadResult
.
code
==
200
&&
uploadResult
.
data
&&
uploadResult
.
data
.
length
)
{
imageUploadUrl
=
uploadResult
.
data
[
0
]
}
else
{
throw
new
Error
(
'
图像上传失败。
'
)
}
}
catch
(
err
)
{
this
.
error
=
err
.
message
this
.
loading
=
false
return
}
let
params
=
{}
params
[
'
real-esrgan@nightmareai
'
]
=
{
image
:
imageUploadUrl
,
scale
:
2
,
face_enhance
:
false
,
}
let
res
=
await
aonet
.
prediction
([
'
real-esrgan@nightmareai
'
],
{
...
params
})
if
(
res
.
code
===
200
&&
res
.
data
)
{
let
taskId
=
res
.
data
.
task_id
let
timing
=
setInterval
(
async
()
=>
{
try
{
let
res
=
await
aonet
.
task
(
taskId
)
if
(
res
.
code
===
200
&&
res
.
data
)
{
res
=
res
.
data
if
(
res
.
status
!==
0
)
{
this
.
progress
=
100
}
if
(
res
.
status
==
3
||
res
.
status
==
4
)
{
let
msg
=
(
res
.
error
&&
res
.
error
)
||
'
操作超时
'
throw
new
Error
(
msg
)
}
if
(
res
.
status
==
2
)
{
this
.
resultImage
=
res
.
result
[
'
real-esrgan@nightmareai
'
][
0
]
this
.
loading
=
false
clearInterval
(
timing
)
}
}
if
(
res
.
code
===
201
)
{
clearInterval
(
timing
)
throw
new
Error
(
res
.
message
)
}
}
catch
(
error
)
{
this
.
error
=
error
.
message
this
.
loading
=
false
clearInterval
(
timing
)
}
},
1000
)
}
else
{
this
.
error
=
res
.
message
||
'
请求失败。
'
this
.
loading
=
false
}
},
downloadImage
()
{
const
link
=
document
.
createElement
(
'
a
'
)
link
.
href
=
this
.
resultImage
link
.
download
=
'
upscaled-image.png
'
document
.
body
.
appendChild
(
link
)
link
.
click
()
document
.
body
.
removeChild
(
link
)
},
},
}
</
script
>
<
template
>
<header>
<img
alt=
"Vue logo"
class=
"logo"
src=
"./assets/logo.svg"
width=
"125"
height=
"125"
/>
<
style
>
.app-container
{
min-height
:
100vh
;
display
:
flex
;
flex-direction
:
column
;
}
<div
class=
"wrapper"
>
<HelloWorld
msg=
"You did it!"
/>
</div>
</header>
.el-header
{
background-color
:
#409eff
;
color
:
white
;
text-align
:
center
;
padding
:
20px
;
}
<main>
<TheWelcome
/>
</main>
</
template
>
.el-main
{
flex
:
1
;
display
:
flex
;
flex-direction
:
column
;
align-items
:
center
;
}
<
style
scoped
>
header
{
line-height
:
1.5
;
.upload-demo
{
margin-top
:
20px
;
}
.logo
{
display
:
block
;
margin
:
0
auto
2rem
;
.loading-col
{
text-align
:
center
;
}
@media
(
min-width
:
1024px
)
{
header
{
display
:
flex
;
place-items
:
center
;
padding-right
:
calc
(
var
(
--section-gap
)
/
2
);
}
.error-col
{
margin-top
:
20px
;
}
.logo
{
margin
:
0
2rem
0
0
;
}
.result-col
{
text-align
:
center
;
margin-top
:
20px
;
}
header
.wrapper
{
display
:
flex
;
place-items
:
flex-start
;
flex-wrap
:
wrap
;
}
.result-image
{
max-width
:
80%
;
height
:
auto
;
margin-bottom
:
20px
;
}
</
style
>
src/main.js
浏览文件 @
70f9dcef
// src/main.js
import
{
createApp
}
from
'
vue
'
import
App
from
'
./App.vue
'
import
ElementPlus
from
'
element-plus
'
import
'
element-plus/dist/index.css
'
import
'
./assets/main.css
'
createApp
(
App
)
.
mount
(
'
#app
'
)
const
app
=
createApp
(
App
)
app
.
use
(
ElementPlus
)
app
.
mount
(
'
#app
'
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录