Update index.html
Browse files- index.html +160 -156
index.html
CHANGED
@@ -1,172 +1,176 @@
|
|
1 |
<html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
<!-- import vue -->
|
7 |
-
<script src="https://unpkg.com/vue@next"></script>
|
8 |
-
<!-- import Elm CSS -->
|
9 |
-
<link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
|
10 |
-
<!-- import Elm JavaScript -->
|
11 |
-
<script src="https://unpkg.com/element-plus"></script>
|
12 |
-
<!-- import axios -->
|
13 |
-
<script src="https://unpkg.com/axios@1.1.2/dist/axios.min.js"></script>
|
14 |
-
<title>mj</title>
|
15 |
-
<style>
|
16 |
-
body {
|
17 |
-
display: flex;
|
18 |
-
justify-content: center;
|
19 |
-
background-color: #f5f5f5;
|
20 |
-
}
|
21 |
-
|
22 |
-
#app {
|
23 |
-
width: 1000px;
|
24 |
-
}
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
</head>
|
39 |
|
40 |
-
<body>
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
<p>
|
54 |
-
<el-button type="primary" @click="getResult(item.msg_Id)">刷新</el-button>
|
55 |
-
</p>
|
56 |
-
<template v-if="item.result">
|
57 |
-
<el-image fit="scale-down" lazy :src="item.result.url" :alt="item.question"></el-image>
|
58 |
<p>
|
59 |
-
<el-button type="primary"
|
60 |
-
<el-button type="primary" plain @click="variation(item, 2)">V2</el-button>
|
61 |
-
<el-button type="primary" plain @click="variation(item, 3)">V3</el-button>
|
62 |
-
<el-button type="primary" plain @click="variation(item, 4)">V4</el-button>
|
63 |
</p>
|
64 |
-
<
|
65 |
-
<el-
|
66 |
-
<
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
</template>
|
74 |
-
</
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
</div>
|
83 |
</div>
|
84 |
</div>
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
};
|
96 |
-
},
|
97 |
-
mounted() {
|
98 |
-
this.initTask()
|
99 |
-
this.getOtherCase()
|
100 |
-
},
|
101 |
-
methods: {
|
102 |
-
initTask() {
|
103 |
-
this.tasks = JSON.parse(window.localStorage.getItem('task') || JSON.stringify([]))
|
104 |
},
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
return
|
109 |
-
}
|
110 |
-
this.msg_Id = grs()
|
111 |
-
this.loading = true
|
112 |
-
axios({
|
113 |
-
method: 'post',
|
114 |
-
url: 'https://gghfpp.laf.dev/mj-func',
|
115 |
-
data: {
|
116 |
-
type: 'imagine',
|
117 |
-
param: {
|
118 |
-
msg_Id: this.msg_Id,
|
119 |
-
question: this.question
|
120 |
-
}
|
121 |
-
}
|
122 |
-
}).then(res => {
|
123 |
-
console.log('[ res ] >', res)
|
124 |
-
this.$message.success("上传成功,正在画图,请稍后...")
|
125 |
-
window.localStorage.setItem('task', JSON.stringify([
|
126 |
-
{ msg_Id: this.msg_Id, question: this.question, result: null },
|
127 |
-
...this.tasks
|
128 |
-
]))
|
129 |
-
this.initTask()
|
130 |
-
this.getResult(this.msg_Id)
|
131 |
-
}).catch(err => {
|
132 |
-
console.log('[ err ] >', err)
|
133 |
-
}).finally(() => {
|
134 |
-
this.loading = false
|
135 |
-
})
|
136 |
},
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
variation({ result, question, msg_Id }, index) {
|
171 |
console.log(result, question, index);
|
172 |
// this.$message.warning('正在努力开发中...')
|
|
|
1 |
<html>
|
2 |
+
<head>
|
3 |
+
<meta charset="UTF-8" />
|
4 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
5 |
+
<!-- import vue -->
|
6 |
+
<script src="https://unpkg.com/vue@next"></script>
|
7 |
+
<!-- import Elm CSS -->
|
8 |
+
<link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
|
9 |
+
<!-- import Elm JavaScript -->
|
10 |
+
<script src="https://unpkg.com/element-plus"></script>
|
11 |
+
<!-- import axios -->
|
12 |
+
<script src="https://unpkg.com/axios@1.1.2/dist/axios.min.js"></script>
|
13 |
+
<title>mj</title>
|
14 |
+
<style>
|
15 |
+
body {
|
16 |
+
display: flex;
|
17 |
+
justify-content: center;
|
18 |
+
background-color: #f5f5f5;
|
19 |
+
}
|
20 |
|
21 |
+
#app {
|
22 |
+
width: 1000px;
|
23 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
.task {
|
26 |
+
border: 1px solid #ddd;
|
27 |
+
background-color: #fff;
|
28 |
+
border-radius: 10px;
|
29 |
+
margin-bottom: 20px;
|
30 |
+
padding: 20px;
|
31 |
+
}
|
32 |
|
33 |
+
image {
|
34 |
+
border-radius: 10px;
|
35 |
+
}
|
36 |
+
</style>
|
37 |
+
</head>
|
38 |
|
39 |
+
<body>
|
40 |
+
<div id="app">
|
41 |
+
<el-form label-position="top">
|
42 |
+
<el-form-item label="请输入要生成的图片内容,尽量使用英文">
|
43 |
+
<el-input type="textarea" v-model="question" placeholder="例如:A golden Labrador dog"></el-input>
|
44 |
+
<el-button style="margin-top: 10px;" type="primary" @click="submit" :loading="loading">提交</el-button>
|
45 |
+
</el-form-item>
|
46 |
+
</el-form>
|
47 |
+
<div class="result" style="margin-top: 10px;">
|
48 |
+
<h1>我的作品</h1>
|
49 |
+
<div v-for="(item, index) in tasks" class="task" :key="item.msg_Id">
|
50 |
+
<p>任务id:<el-button link type="primary">{{item.msg_Id}}</el-button> </p>
|
51 |
+
<p>{{item.question}}</p>
|
|
|
|
|
|
|
|
|
|
|
52 |
<p>
|
53 |
+
<el-button type="primary" @click="getResult(item.msg_Id)">刷新</el-button>
|
|
|
|
|
|
|
54 |
</p>
|
55 |
+
<template v-if="item.result">
|
56 |
+
<el-image fit="scale-down" lazy :src="item.result.url" :alt="item.question"></el-image>
|
57 |
+
<p>
|
58 |
+
<el-button type="primary" plain @click="variation(item, 1)">V1</el-button>
|
59 |
+
<el-button type="primary" plain @click="variation(item, 2)">V2</el-button>
|
60 |
+
<el-button type="primary" plain @click="variation(item, 3)">V3</el-button>
|
61 |
+
<el-button type="primary" plain @click="variation(item, 4)">V4</el-button>
|
62 |
+
</p>
|
63 |
+
<p>
|
64 |
+
<el-button type="primary" plain @click="upscale(item, 1)">U1</el-button>
|
65 |
+
<el-button type="primary" plain @click="upscale(item, 2)">U2</el-button>
|
66 |
+
<el-button type="primary" plain @click="upscale(item, 3)">U3</el-button>
|
67 |
+
<el-button type="primary" plain @click="upscale(item, 4)">U4</el-button>
|
68 |
+
</p>
|
69 |
+
<template v-if="item.result.upscaleUrl">
|
70 |
+
<h5>大图</h5>
|
71 |
+
<el-image fit="scale-down" lazy :src="item.result.upscaleUrl" :alt="item.question"></el-image>
|
72 |
+
</template>
|
73 |
</template>
|
74 |
+
</div>
|
75 |
+
<h2>其他人的作品(最近10个)</h2>
|
76 |
+
<div v-for="item in otherCase" :key="item.id" class="task">
|
77 |
+
<h3>prompt:{{ formatPrompt(item.content) }}</h3>
|
78 |
+
<h3>time:{{ formatDate(item.timestamp) }}</h3>
|
79 |
+
<div v-for="attachment in item.attachments" :key="attachment.id">
|
80 |
+
<el-image fit="scale-down" lazy :src="attachment.url" :alt="formatPrompt(item.content)"></el-image>
|
81 |
+
</div>
|
82 |
</div>
|
83 |
</div>
|
84 |
</div>
|
85 |
+
<script>
|
86 |
+
const App = {
|
87 |
+
data() {
|
88 |
+
return {
|
89 |
+
question: "",
|
90 |
+
msg_Id: "",
|
91 |
+
loading: false,
|
92 |
+
tasks: [],
|
93 |
+
otherCase: [],
|
94 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
},
|
96 |
+
mounted() {
|
97 |
+
this.initTask();
|
98 |
+
this.getOtherCase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
},
|
100 |
+
methods: {
|
101 |
+
initTask() {
|
102 |
+
this.tasks = JSON.parse(window.localStorage.getItem("task") || JSON.stringify([]));
|
103 |
+
},
|
104 |
+
submit() {
|
105 |
+
if (!this.question) {
|
106 |
+
this.$message.error("请输入图片内容");
|
107 |
+
return;
|
108 |
+
}
|
109 |
+
this.msg_Id = grs();
|
110 |
+
this.loading = true;
|
111 |
+
axios({
|
112 |
+
method: "post",
|
113 |
+
url: "https://gghfpp.laf.dev/mj-func",
|
114 |
+
data: {
|
115 |
+
type: "imagine",
|
116 |
+
param: {
|
117 |
+
msg_Id: this.msg_Id,
|
118 |
+
question: this.question,
|
119 |
+
},
|
120 |
+
},
|
121 |
+
})
|
122 |
+
.then((res) => {
|
123 |
+
console.log("[ res ] >", res);
|
124 |
+
this.$message.success("上传成功,正在画图,请稍后...");
|
125 |
+
window.localStorage.setItem(
|
126 |
+
"task",
|
127 |
+
JSON.stringify([{ msg_Id: this.msg_Id, question: this.question, result: null }, ...this.tasks])
|
128 |
+
);
|
129 |
+
this.initTask();
|
130 |
+
this.getResult(this.msg_Id);
|
131 |
+
})
|
132 |
+
.catch((err) => {
|
133 |
+
console.log("[ err ] >", err);
|
134 |
+
})
|
135 |
+
.finally(() => {
|
136 |
+
this.loading = false;
|
137 |
+
});
|
138 |
+
},
|
139 |
+
getResult(msg_Id) {
|
140 |
+
axios({
|
141 |
+
method: "post",
|
142 |
+
url: "https://gghfpp.laf.dev/mj-func",
|
143 |
+
data: {
|
144 |
+
type: "retrieveMessages",
|
145 |
+
},
|
146 |
+
})
|
147 |
+
.then((res) => {
|
148 |
+
console.log("[ res ] >", res);
|
149 |
+
const { data } = res;
|
150 |
+
const resIndex = data.findIndex((item) => item.content.includes(msg_Id));
|
151 |
+
if (resIndex < 0) {
|
152 |
+
this.$message.success("正在努力生成,请耐心等待");
|
153 |
+
return;
|
154 |
+
}
|
155 |
+
const { id, attachments } = data[resIndex];
|
156 |
+
if (!attachments.length) {
|
157 |
+
this.$message.success("正在努力生成,请耐心等待");
|
158 |
+
return;
|
159 |
+
}
|
160 |
+
const { pic } = attachments[0];
|
161 |
+
if (pic) {
|
162 |
+
const myIndex = this.tasks.findIndex((item) => item.msg_Id == msg_Id);
|
163 |
+
this.tasks[myIndex].result = { id, url: pic };
|
164 |
+
window.localStorage.setItem("task", JSON.stringify(this.tasks));
|
165 |
+
} else {
|
166 |
+
this.$message.success("正在努力生成,请耐心等待");
|
167 |
+
return;
|
168 |
+
}
|
169 |
+
})
|
170 |
+
.catch((err) => {
|
171 |
+
console.log("[ err ] >", err);
|
172 |
+
});
|
173 |
+
},
|
174 |
variation({ result, question, msg_Id }, index) {
|
175 |
console.log(result, question, index);
|
176 |
// this.$message.warning('正在努力开发中...')
|