feat: mobile page refactor is finished

This commit is contained in:
RockYang 2024-04-29 19:22:00 +08:00
parent 3b081ff0f4
commit 51a8f42d89
11 changed files with 181 additions and 87 deletions

View File

@ -263,7 +263,7 @@ func (s *Service) CheckTaskStatus() {
go func() { go func() {
logger.Info("Running Stable-Diffusion task status checking ...") logger.Info("Running Stable-Diffusion task status checking ...")
for { for {
var jobs []model.SdJob var jobs []model.DallJob
res := s.db.Where("progress < ?", 100).Find(&jobs) res := s.db.Where("progress < ?", 100).Find(&jobs)
if res.Error != nil { if res.Error != nil {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
@ -287,7 +287,7 @@ func (s *Service) CheckTaskStatus() {
Balance: user.Power + job.Power, Balance: user.Power + job.Power,
Mark: types.PowerAdd, Mark: types.PowerAdd,
Model: "dall-e-3", Model: "dall-e-3",
Remark: fmt.Sprintf("任务失败退回算力。任务ID%s", job.TaskId), Remark: fmt.Sprintf("任务失败退回算力。任务ID%d", job.Id),
CreatedAt: time.Now(), CreatedAt: time.Now(),
}) })
} }

View File

@ -74,6 +74,10 @@
} }
.pt-6 {
padding 15px 10px
}
.tip-text { .tip-text {
padding 10px padding 10px
line-height 1.5 line-height 1.5

View File

@ -81,7 +81,7 @@
.pt-6 { .pt-6 {
padding 10px padding 15px 10px
} }
.tip-text { .tip-text {

View File

@ -9,17 +9,21 @@
> >
<div class="form"> <div class="form">
<el-form :model="form" label-width="120px" label-position="left"> <el-form :model="form" label-width="80px" label-position="left">
<el-form-item label="用户名"> <el-form-item label="用户名">
<el-input v-model="form.username" placeholder="手机号/邮箱地址"/> <el-input v-model="form.username" placeholder="手机号/邮箱地址"/>
</el-form-item> </el-form-item>
<el-form-item label="验证码"> <el-form-item label="验证码">
<div class="code-box">
<el-input v-model="form.code" maxlength="6"/>
<send-msg size="" :receiver="form.username" style="margin-left: 10px; min-width: 100px"/>
</div>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="16"> <el-col :span="12">
<el-input v-model="form.code" maxlength="6"/>
</el-col> </el-col>
<el-col :span="8"> <el-col :span="12" style="justify-content: right">
<send-msg size="" :receiver="form.username"/>
</el-col> </el-col>
</el-row> </el-row>
</el-form-item> </el-form-item>
@ -97,9 +101,13 @@ const close = function () {
<style lang="stylus"> <style lang="stylus">
.reset-pass { .reset-pass {
.form { .form {
padding 10px 40px padding 10px 20px
}
.code-box {
display: flex;
justify-content: space-between;
width: 100%
} }
.el-dialog__footer { .el-dialog__footer {
text-align center text-align center
} }

View File

@ -2,7 +2,6 @@
* Util lib functions * Util lib functions
*/ */
import {showConfirmDialog} from "vant"; import {showConfirmDialog} from "vant";
import {useRouter} from "vue-router";
// generate a random string // generate a random string
export function randString(length) { export function randString(length) {
@ -231,7 +230,7 @@ export function showLoginDialog(router) {
showConfirmDialog({ showConfirmDialog({
title: '登录', title: '登录',
message: message:
'当前操作需要登录才能进行,前往登录?', '操作需要登录才能进行,前往登录?',
}).then(() => { }).then(() => {
router.push("/login") router.push("/login")
}).catch(() => { }).catch(() => {

View File

@ -34,9 +34,10 @@
<el-button class="login-btn" size="large" type="primary" @click="login">登录</el-button> <el-button class="login-btn" size="large" type="primary" @click="login">登录</el-button>
</el-row> </el-row>
<el-row class="text-line" :gutter="20"> <el-row class="opt" :gutter="20">
<el-button type="primary" @click="router.push('/register')" size="small" plain>注册新账号</el-button> <el-col :span="8"><el-link type="primary" @click="router.push('/register')">注册</el-link></el-col>
<el-button type="success" @click="showResetPass = true" size="small" plain>重置密码</el-button> <el-col :span="8"><el-link @click="showResetPass = true">重置密码</el-link></el-col>
<el-col :span="8"><el-link @click="router.push('/')">首页</el-link></el-col>
</el-row> </el-row>
</div> </div>
</div> </div>
@ -196,6 +197,13 @@ const login = function () {
padding-top 10px; padding-top 10px;
font-size 14px; font-size 14px;
} }
.opt {
padding 15px
.el-col {
text-align center
}
}
} }
} }

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="app-background"> <div class="app-background">
<div v-if="isLogin" class="container mobile-chat-list"> <div class="container mobile-chat-list">
<van-nav-bar <van-nav-bar
:title="title" :title="title"
left-text="新建会话" left-text="新建会话"
@ -82,7 +82,7 @@ import {httpGet, httpPost} from "@/utils/http";
import {showConfirmDialog, showFailToast, showSuccessToast} from "vant"; import {showConfirmDialog, showFailToast, showSuccessToast} from "vant";
import {checkSession} from "@/action/session"; import {checkSession} from "@/action/session";
import {router} from "@/router"; import {router} from "@/router";
import {removeArrayItem} from "@/utils/libs"; import {removeArrayItem, showLoginDialog} from "@/utils/libs";
const title = ref("会话列表") const title = ref("会话列表")
const chatName = ref("") const chatName = ref("")
@ -135,20 +135,53 @@ checkSession().then((user) => {
}) })
}).catch(() => { }).catch(() => {
router.push("/login") loading.value = false
finished.value = true
//
httpGet('/api/role/list').then((res) => {
if (res.data) {
const items = res.data
for (let i = 0; i < items.length; i++) {
// console.log(items[i])
roles.value.push({
text: items[i].name,
value: items[i].id,
icon: items[i].icon,
helloMsg: items[i].hello_msg
})
}
}
}).catch(() => {
showFailToast("加载聊天角色失败")
})
//
httpGet('/api/model/list').then(res => {
if (res.data) {
const items = res.data
for (let i = 0; i < items.length; i++) {
models.value.push({text: items[i].name, value: items[i].id})
}
}
}).catch(e => {
showFailToast("加载模型失败: " + e.message)
})
}) })
const onLoad = () => { const onLoad = () => {
httpGet("/api/chat/list?user_id=" + loginUser.value.id).then((res) => { checkSession().then(() => {
if (res.data) { httpGet("/api/chat/list?user_id=" + loginUser.value.id).then((res) => {
chats.value = res.data; if (res.data) {
allChats.value = res.data; chats.value = res.data;
finished.value = true allChats.value = res.data;
} finished.value = true
loading.value = false; }
}).catch(() => { loading.value = false;
error.value = true }).catch(() => {
showFailToast("加载会话列表失败") error.value = true
showFailToast("加载会话列表失败")
})
}) })
}; };
@ -167,6 +200,10 @@ const search = () => {
} }
const clearAllChatHistory = () => { const clearAllChatHistory = () => {
if (!isLogin.value) {
return showLoginDialog(router)
}
showConfirmDialog({ showConfirmDialog({
title: '操作提示', title: '操作提示',
message: '确定要删除所有的会话记录吗?' message: '确定要删除所有的会话记录吗?'
@ -183,6 +220,9 @@ const clearAllChatHistory = () => {
} }
const newChat = (item) => { const newChat = (item) => {
if (!isLogin.value) {
return showLoginDialog(router)
}
showPicker.value = false showPicker.value = false
const options = item.selectedOptions const options = item.selectedOptions
// setChatConfig({ // setChatConfig({

View File

@ -50,7 +50,7 @@
<van-image :src="item.icon" /> <van-image :src="item.icon" />
</div> </div>
<div class="info"> <div class="info">
<div class="info-title">{{item.name}}{{item.name}}{{item.name}}{{item.name}}</div> <div class="info-title">{{item.name}}</div>
<div class="info-text">{{item.hello_msg}}</div> <div class="info-text">{{item.hello_msg}}</div>
</div> </div>
</div> </div>

View File

@ -1,33 +1,34 @@
<template> <template>
<div class="mobile-user-profile container"> <div class="mobile-user-profile container">
<van-nav-bar :title="title"/>
<div class="content"> <div class="content">
<van-form> <van-form>
<div class="avatar">
<van-uploader v-model="fileList"
reupload max-count="1"
:deletable="false"
:after-read="afterRead"/>
</div>
<van-cell-group inset v-model="form"> <van-cell-group inset v-model="form">
<van-field <van-field
v-model="form.username" v-model="form.username"
name="账号"
label="账号" label="账号"
readonly readonly
disabled disabled
/> />
<van-field label="头像"> <van-field
<template #input> v-model="form.nickname"
<van-uploader v-model="fileList" label="昵称"
reupload max-count="1" readonly
:deletable="false" disabled
:after-read="afterRead"/> />
</template>
</van-field>
<van-field label="剩余算力"> <van-field label="算力">
<template #input> <template #input>
<van-tag type="primary">{{ form.power }}</van-tag> <van-tag type="primary">{{ form.power }}</van-tag>
</template> </template>
</van-field> </van-field>
<van-field label="会员有效期" v-if="form.expired_time > 0"> <van-field label="有效期" v-if="form.expired_time > 0">
<template #input> <template #input>
<van-tag type="warning">{{ dateFormat(form.expired_time) }}</van-tag> <van-tag type="warning">{{ dateFormat(form.expired_time) }}</van-tag>
</template> </template>
@ -36,8 +37,15 @@
</van-cell-group> </van-cell-group>
</van-form> </van-form>
<div class="modify-pass"> <div class="opt" v-if="isLogin">
<van-button round block type="primary" @click="showPasswordDialog = true">修改密码</van-button> <van-row :gutter="10">
<van-col :span="12">
<van-button round block type="primary" @click="showPasswordDialog = true">修改密码</van-button>
</van-col>
<van-col :span="12">
<van-button round block @click="logout">退出登录</van-button>
</van-col>
</van-row>
</div> </div>
<div class="product-list"> <div class="product-list">
@ -114,23 +122,22 @@ import {onMounted, ref} from "vue";
import {showFailToast, showNotify, showSuccessToast} from "vant"; import {showFailToast, showNotify, showSuccessToast} from "vant";
import {httpGet, httpPost} from "@/utils/http"; import {httpGet, httpPost} from "@/utils/http";
import Compressor from 'compressorjs'; import Compressor from 'compressorjs';
import {dateFormat} from "@/utils/libs"; import {dateFormat, showLoginDialog} from "@/utils/libs";
import {ElMessage} from "element-plus"; import {ElMessage} from "element-plus";
import {checkSession} from "@/action/session"; import {checkSession} from "@/action/session";
import {useRouter} from "vue-router"; import {useRouter} from "vue-router";
import {removeUserToken} from "@/store/session";
const title = ref('用户设置')
const form = ref({ const form = ref({
username: '', username: 'GeekMaster',
nickname: '', nickname: '极客学长@001',
mobile: '', mobile: '1300000000',
avatar: '', avatar: '',
calls: 0, power: 0,
tokens: 0
}) })
const fileList = ref([ const fileList = ref([
{ {
url: '', url: '/images/user-info.png',
message: '上传中...', message: '上传中...',
} }
]); ]);
@ -139,11 +146,13 @@ const products = ref([])
const vipMonthPower = ref(0) const vipMonthPower = ref(0)
const payWays = ref({}) const payWays = ref({})
const router = useRouter() const router = useRouter()
const loginUser = ref(null) const userId = ref(0)
const isLogin = ref(false)
onMounted(() => { onMounted(() => {
checkSession().then(user => { checkSession().then(user => {
loginUser.value = user userId.value = user.id
isLogin.value = true
httpGet('/api/user/profile').then(res => { httpGet('/api/user/profile').then(res => {
form.value = res.data form.value = res.data
fileList.value[0].url = form.value.avatar fileList.value[0].url = form.value.avatar
@ -151,28 +160,27 @@ onMounted(() => {
console.log(e.message) console.log(e.message)
showFailToast('获取用户信息失败') showFailToast('获取用户信息失败')
}); });
//
httpGet("/api/product/list").then((res) => {
products.value = res.data
}).catch(e => {
showFailToast("获取产品套餐失败:" + e.message)
})
httpGet("/api/config/get?key=system").then(res => {
vipMonthPower.value = res.data['vip_month_power']
}).catch(e => {
showFailToast("获取系统配置失败:" + e.message)
})
httpGet("/api/payment/payWays").then(res => {
payWays.value = res.data
}).catch(e => {
ElMessage.error("获取支付方式失败:" + e.message)
})
}).catch(() => { }).catch(() => {
router.push("/login")
})
//
httpGet("/api/product/list").then((res) => {
products.value = res.data
}).catch(e => {
showFailToast("获取产品套餐失败:" + e.message)
})
httpGet("/api/config/get?key=system").then(res => {
vipMonthPower.value = res.data['vip_month_power']
}).catch(e => {
showFailToast("获取系统配置失败:" + e.message)
})
httpGet("/api/payment/payWays").then(res => {
payWays.value = res.data
}).catch(e => {
ElMessage.error("获取支付方式失败:" + e.message)
}) })
}) })
@ -244,10 +252,14 @@ const updatePass = () => {
} }
const pay = (payWay, item) => { const pay = (payWay, item) => {
if (!isLogin.value) {
return showLoginDialog(router)
}
httpPost("/api/payment/mobile", { httpPost("/api/payment/mobile", {
pay_way: payWay, pay_way: payWay,
product_id: item.id, product_id: item.id,
user_id: loginUser.value.id user_id: userId.value
}).then(res => { }).then(res => {
// console.log(res.data) // console.log(res.data)
location.href = res.data location.href = res.data
@ -255,20 +267,38 @@ const pay = (payWay, item) => {
showFailToast("生成支付订单失败:" + e.message) showFailToast("生成支付订单失败:" + e.message)
}) })
} }
const logout = function () {
httpGet('/api/user/logout').then(() => {
removeUserToken();
router.push('/');
}).catch(() => {
showFailToast('注销失败!');
})
}
</script> </script>
<style lang="stylus"> <style lang="stylus">
.mobile-user-profile { .mobile-user-profile {
.content { .content {
padding-top 46px padding-top 15px
padding-bottom 60px padding-bottom 60px
.avatar {
display flex
justify-content center
.van-image {
border-radius 50%
}
}
.van-field__label { .van-field__label {
width 100px width 100px
text-align right text-align right
} }
.modify-pass { .opt {
padding 10px 15px padding 10px 15px
} }

View File

@ -161,7 +161,7 @@
</van-collapse> </van-collapse>
</div> </div>
<div class="text-line"> <div class="text-line pt-6">
<el-tag>绘图消耗{{ mjPower }}算力U/V 操作消耗{{ mjActionPower }}算力当前算力{{ power }}</el-tag> <el-tag>绘图消耗{{ mjPower }}算力U/V 操作消耗{{ mjActionPower }}算力当前算力{{ power }}</el-tag>
</div> </div>
@ -290,6 +290,7 @@ import {getSessionId} from "@/store/session";
import {checkSession} from "@/action/session"; import {checkSession} from "@/action/session";
import {useRouter} from "vue-router"; import {useRouter} from "vue-router";
import {Delete} from "@element-plus/icons-vue"; import {Delete} from "@element-plus/icons-vue";
import {showLoginDialog} from "@/utils/libs";
const activeColspan = ref([""]) const activeColspan = ref([""])
@ -335,18 +336,19 @@ const finishedJobs = ref([])
const socket = ref(null) const socket = ref(null)
const power = ref(0) const power = ref(0)
const activeName = ref("txt2img") const activeName = ref("txt2img")
const isLogin = ref(false)
onMounted(() => { onMounted(() => {
checkSession().then(user => { checkSession().then(user => {
power.value = user['power'] power.value = user['power']
userId.value = user.id userId.value = user.id
isLogin.value = true
fetchRunningJobs() fetchRunningJobs()
fetchFinishJobs(1) fetchFinishJobs(1)
connect() connect()
}).catch(() => { }).catch(() => {
router.push('/login') // router.push('/login')
}); });
}) })
@ -564,6 +566,10 @@ const variation = (index, item) => {
} }
const generate = () => { const generate = () => {
if (!isLogin.value) {
return showLoginDialog(router)
}
if (params.value.prompt === '' && params.value.task_type === "image") { if (params.value.prompt === '' && params.value.task_type === "image") {
return showFailToast("请输入绘画提示词!") return showFailToast("请输入绘画提示词!")
} }

View File

@ -228,12 +228,12 @@ import {
showSuccessToast, showSuccessToast,
showToast showToast
} from "vant"; } from "vant";
import {showLoginDialog} from "@/utils/libs";
const listBoxHeight = ref(window.innerHeight - 40) const listBoxHeight = ref(window.innerHeight - 40)
const mjBoxHeight = ref(window.innerHeight - 150) const mjBoxHeight = ref(window.innerHeight - 150)
const showTaskDialog = ref(false) const showTaskDialog = ref(false)
const item = ref({}) const item = ref({})
const showLoginDialog = ref(false)
const isLogin = ref(false) const isLogin = ref(false)
const activeColspan = ref([""]) const activeColspan = ref([""])
@ -429,16 +429,15 @@ const onLoad = () => {
// //
const promptRef = ref(null) const promptRef = ref(null)
const generate = () => { const generate = () => {
if (!isLogin.value) {
return showLoginDialog(router)
}
if (params.value.prompt === '') { if (params.value.prompt === '') {
promptRef.value.focus() promptRef.value.focus()
return showToast("请输入绘画提示词!") return showToast("请输入绘画提示词!")
} }
if (!isLogin.value) {
showLoginDialog.value = true
return
}
if (params.value.seed === '') { if (params.value.seed === '') {
params.value.seed = -1 params.value.seed = -1
} }