mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
feat: midjourney mobile page all function is ready
This commit is contained in:
parent
d2ac807252
commit
8ab15e5dc4
@ -141,6 +141,11 @@ func (h *MidJourneyHandler) Image(c *gin.Context) {
|
|||||||
prompt += fmt.Sprintf(" %s", data.Model)
|
prompt += fmt.Sprintf(" %s", data.Model)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理融图和换脸的提示词
|
||||||
|
if data.TaskType == types.TaskSwapFace.String() || data.TaskType == types.TaskBlend.String() {
|
||||||
|
prompt = fmt.Sprintf("%s:%s", data.TaskType, strings.Join(data.ImgArr, ","))
|
||||||
|
}
|
||||||
|
|
||||||
idValue, _ := c.Get(types.LoginUserID)
|
idValue, _ := c.Get(types.LoginUserID)
|
||||||
userId := utils.IntValue(utils.InterfaceToString(idValue), 0)
|
userId := utils.IntValue(utils.InterfaceToString(idValue), 0)
|
||||||
// generate task id
|
// generate task id
|
||||||
|
@ -58,12 +58,12 @@ func (s *Service) Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if it's reference message, check if it's this channel's message
|
// if it's reference message, check if it's this channel's message
|
||||||
if task.ChannelId != "" && task.ChannelId != s.Name {
|
//if task.ChannelId != "" && task.ChannelId != s.Name {
|
||||||
logger.Debugf("handle other service task, name: %s, channel_id: %s, drop it.", s.Name, task.ChannelId)
|
// logger.Debugf("handle other service task, name: %s, channel_id: %s, drop it.", s.Name, task.ChannelId)
|
||||||
s.taskQueue.RPush(task)
|
// s.taskQueue.RPush(task)
|
||||||
time.Sleep(time.Second)
|
// time.Sleep(time.Second)
|
||||||
continue
|
// continue
|
||||||
}
|
//}
|
||||||
|
|
||||||
logger.Infof("%s handle a new MidJourney task: %+v", s.Name, task)
|
logger.Infof("%s handle a new MidJourney task: %+v", s.Name, task)
|
||||||
var res ImageRes
|
var res ImageRes
|
||||||
@ -85,14 +85,15 @@ func (s *Service) Run() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var job model.MidJourneyJob
|
||||||
|
s.db.Where("id = ?", task.Id).First(&job)
|
||||||
if err != nil || (res.Code != 1 && res.Code != 22) {
|
if err != nil || (res.Code != 1 && res.Code != 22) {
|
||||||
errMsg := fmt.Sprintf("%v,%s", err, res.Description)
|
errMsg := fmt.Sprintf("%v,%s", err, res.Description)
|
||||||
logger.Error("绘画任务执行失败:", errMsg)
|
logger.Error("绘画任务执行失败:", errMsg)
|
||||||
|
job.Progress = -1
|
||||||
|
job.ErrMsg = errMsg
|
||||||
// update the task progress
|
// update the task progress
|
||||||
s.db.Model(&model.MidJourneyJob{Id: task.Id}).UpdateColumns(map[string]interface{}{
|
s.db.Updates(&job)
|
||||||
"progress": -1,
|
|
||||||
"err_msg": errMsg,
|
|
||||||
})
|
|
||||||
// 任务失败,通知前端
|
// 任务失败,通知前端
|
||||||
s.notifyQueue.RPush(task.UserId)
|
s.notifyQueue.RPush(task.UserId)
|
||||||
// restore img_call quota
|
// restore img_call quota
|
||||||
@ -108,11 +109,9 @@ func (s *Service) Run() {
|
|||||||
s.taskStartTimes[int(task.Id)] = time.Now()
|
s.taskStartTimes[int(task.Id)] = time.Now()
|
||||||
atomic.AddInt32(&s.HandledTaskNum, 1)
|
atomic.AddInt32(&s.HandledTaskNum, 1)
|
||||||
// 更新任务 ID/频道
|
// 更新任务 ID/频道
|
||||||
s.db.Model(&model.MidJourneyJob{Id: task.Id}).UpdateColumns(map[string]interface{}{
|
job.TaskId = res.Result
|
||||||
"task_id": res.Result,
|
job.ChannelId = s.Name
|
||||||
"channel_id": s.Name,
|
s.db.Updates(&job)
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,3 +131,8 @@
|
|||||||
right: 5px;
|
right: 5px;
|
||||||
top: 5px;
|
top: 5px;
|
||||||
}
|
}
|
||||||
|
.mobile-mj .content .finish-job-list .van-grid .van-grid-item .van-grid-item__content .job-item .remove .el-button {
|
||||||
|
margin-left: 5px;
|
||||||
|
height: auto;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
@ -175,6 +175,12 @@
|
|||||||
position absolute
|
position absolute
|
||||||
right 5px
|
right 5px
|
||||||
top 5px
|
top 5px
|
||||||
|
|
||||||
|
.el-button {
|
||||||
|
margin-left 5px
|
||||||
|
height auto
|
||||||
|
padding 5px
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
@font-face {
|
@font-face {
|
||||||
font-family: "iconfont"; /* Project id 4125778 */
|
font-family: "iconfont"; /* Project id 4125778 */
|
||||||
src: url('iconfont.woff2?t=1705615887594') format('woff2'),
|
src: url('iconfont.woff2?t=1708054962140') format('woff2'),
|
||||||
url('iconfont.woff?t=1705615887594') format('woff'),
|
url('iconfont.woff?t=1708054962140') format('woff'),
|
||||||
url('iconfont.ttf?t=1705615887594') format('truetype');
|
url('iconfont.ttf?t=1708054962140') format('truetype');
|
||||||
}
|
}
|
||||||
|
|
||||||
.iconfont {
|
.iconfont {
|
||||||
@ -13,6 +13,10 @@
|
|||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.icon-prompt:before {
|
||||||
|
content: "\e6ce";
|
||||||
|
}
|
||||||
|
|
||||||
.icon-share-bold:before {
|
.icon-share-bold:before {
|
||||||
content: "\e626";
|
content: "\e626";
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -5,6 +5,13 @@
|
|||||||
"css_prefix_text": "icon-",
|
"css_prefix_text": "icon-",
|
||||||
"description": "",
|
"description": "",
|
||||||
"glyphs": [
|
"glyphs": [
|
||||||
|
{
|
||||||
|
"icon_id": "8017627",
|
||||||
|
"name": "prompt",
|
||||||
|
"font_class": "prompt",
|
||||||
|
"unicode": "e6ce",
|
||||||
|
"unicode_decimal": 59086
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"icon_id": "1132455",
|
"icon_id": "1132455",
|
||||||
"name": "share-bold",
|
"name": "share-bold",
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,39 +3,8 @@
|
|||||||
<van-nav-bar :title="title"/>
|
<van-nav-bar :title="title"/>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<van-form @submit="save" v-model="form">
|
<van-empty description="功能正在开发中"/>
|
||||||
<van-cell-group inset>
|
|
||||||
<van-field
|
|
||||||
v-model="form.chat_config.api_keys.OpenAI"
|
|
||||||
label="OpenAI KEY"
|
|
||||||
placeholder="OpenAI API KEY"
|
|
||||||
/>
|
|
||||||
<van-field
|
|
||||||
v-model="form.chat_config.api_keys.Azure"
|
|
||||||
label="Azure KEY"
|
|
||||||
placeholder="Azure API KEY"
|
|
||||||
/>
|
|
||||||
<van-field
|
|
||||||
v-model="form.chat_config.api_keys.ChatGLM"
|
|
||||||
label="ChatGLM KEY"
|
|
||||||
placeholder="ChatGLM API KEY"
|
|
||||||
/>
|
|
||||||
</van-cell-group>
|
|
||||||
<div style="margin: 16px;">
|
|
||||||
<van-button round block type="primary" native-type="submit">
|
|
||||||
提交
|
|
||||||
</van-button>
|
|
||||||
</div>
|
|
||||||
</van-form>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<van-popup v-model:show="showPicker" round position="bottom">
|
|
||||||
<van-picker
|
|
||||||
:columns="models"
|
|
||||||
@cancel="showPicker = false"
|
|
||||||
@confirm="selectModel"
|
|
||||||
/>
|
|
||||||
</van-popup>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -45,7 +14,7 @@ import {httpGet, httpPost} from "@/utils/http";
|
|||||||
import {showFailToast, showSuccessToast} from "vant";
|
import {showFailToast, showSuccessToast} from "vant";
|
||||||
import {ElMessage} from "element-plus";
|
import {ElMessage} from "element-plus";
|
||||||
|
|
||||||
const title = ref('聊天设置')
|
const title = ref('图片创作广场')
|
||||||
const form = ref({
|
const form = ref({
|
||||||
chat_config: {
|
chat_config: {
|
||||||
api_keys: {OpenAI: "", Azure: "", ChatGLM: ""}
|
api_keys: {OpenAI: "", Azure: "", ChatGLM: ""}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<van-tabbar route v-model="active" @change="onChange">
|
<van-tabbar route v-model="active" @change="onChange">
|
||||||
<van-tabbar-item to="/mobile/chat" name="home" icon="chat-o">对话</van-tabbar-item>
|
<van-tabbar-item to="/mobile/chat" name="home" icon="chat-o">对话</van-tabbar-item>
|
||||||
<van-tabbar-item to="/mobile/mj" name="imageMj" icon="photo-o">绘图</van-tabbar-item>
|
<van-tabbar-item to="/mobile/mj" name="imageMj" icon="photo-o">绘图</van-tabbar-item>
|
||||||
<van-tabbar-item to="/mobile/apps" name="apps" icon="apps-o">应用</van-tabbar-item>
|
<van-tabbar-item to="/mobile/apps" name="apps" icon="apps-o">广场</van-tabbar-item>
|
||||||
<van-tabbar-item to="/mobile/profile" name="profile" icon="user-o">我的</van-tabbar-item>
|
<van-tabbar-item to="/mobile/profile" name="profile" icon="user-o">我的</van-tabbar-item>
|
||||||
</van-tabbar>
|
</van-tabbar>
|
||||||
|
|
||||||
|
@ -190,6 +190,9 @@
|
|||||||
<el-button type="success" v-else @click="publishImage(item, true)" circle>
|
<el-button type="success" v-else @click="publishImage(item, true)" circle>
|
||||||
<i class="iconfont icon-share-bold"></i>
|
<i class="iconfont icon-share-bold"></i>
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button type="primary" @click="showPrompt(item)" circle>
|
||||||
|
<i class="iconfont icon-prompt"></i>
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</van-grid-item>
|
</van-grid-item>
|
||||||
@ -202,7 +205,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {onMounted, ref} from "vue";
|
import {onMounted, ref} from "vue";
|
||||||
import {showFailToast, showNotify, showToast} from "vant";
|
import {showConfirmDialog, showFailToast, showNotify, showToast, showDialog} from "vant";
|
||||||
import {httpGet, httpPost} from "@/utils/http";
|
import {httpGet, httpPost} from "@/utils/http";
|
||||||
import Compressor from "compressorjs";
|
import Compressor from "compressorjs";
|
||||||
import {ElMessage} from "element-plus";
|
import {ElMessage} from "element-plus";
|
||||||
@ -403,6 +406,32 @@ const uploadImg = (file) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const send = (url, index, item) => {
|
||||||
|
httpPost(url, {
|
||||||
|
index: index,
|
||||||
|
channel_id: item.channel_id,
|
||||||
|
message_id: item.message_id,
|
||||||
|
message_hash: item.hash,
|
||||||
|
session_id: getSessionId(),
|
||||||
|
prompt: item.prompt,
|
||||||
|
}).then(() => {
|
||||||
|
ElMessage.success("任务推送成功,请耐心等待任务执行...")
|
||||||
|
imgCalls.value -= 1
|
||||||
|
}).catch(e => {
|
||||||
|
ElMessage.error("任务推送失败:" + e.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 图片放大任务
|
||||||
|
const upscale = (index, item) => {
|
||||||
|
send('/api/mj/upscale', index, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 图片变换任务
|
||||||
|
const variation = (index, item) => {
|
||||||
|
send('/api/mj/variation', index, item)
|
||||||
|
}
|
||||||
|
|
||||||
const generate = () => {
|
const generate = () => {
|
||||||
if (params.value.prompt === '' && params.value.task_type === "image") {
|
if (params.value.prompt === '' && params.value.task_type === "image") {
|
||||||
return showFailToast("请输入绘画提示词!")
|
return showFailToast("请输入绘画提示词!")
|
||||||
@ -420,6 +449,44 @@ const generate = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const removeImage = (item) => {
|
||||||
|
showConfirmDialog({
|
||||||
|
title: '标题',
|
||||||
|
message:
|
||||||
|
'此操作将会删除任务和图片,继续操作码?',
|
||||||
|
}).then(() => {
|
||||||
|
httpPost("/api/mj/remove", {id: item.id, img_url: item.img_url, user_id: userId.value}).then(() => {
|
||||||
|
ElMessage.success("任务删除成功")
|
||||||
|
}).catch(e => {
|
||||||
|
ElMessage.error("任务删除失败:" + e.message)
|
||||||
|
})
|
||||||
|
}).catch(() => {
|
||||||
|
showToast("您取消了操作")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 发布图片到作品墙
|
||||||
|
const publishImage = (item, action) => {
|
||||||
|
let text = "图片发布"
|
||||||
|
if (action === false) {
|
||||||
|
text = "取消发布"
|
||||||
|
}
|
||||||
|
httpPost("/api/mj/publish", {id: item.id, action: action}).then(() => {
|
||||||
|
ElMessage.success(text + "成功")
|
||||||
|
item.publish = action
|
||||||
|
}).catch(e => {
|
||||||
|
ElMessage.error(text + "失败:" + e.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const showPrompt = (item) => {
|
||||||
|
showDialog({
|
||||||
|
title: "绘画提示词",
|
||||||
|
message: item.prompt,
|
||||||
|
}).then(() => {
|
||||||
|
// on close
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="stylus">
|
<style lang="stylus">
|
||||||
|
Loading…
Reference in New Issue
Block a user