mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-22 03:06:38 +08:00
feat: check if the user's chat quota is gt than current chat model required before starting a conversation
This commit is contained in:
parent
5f17ab2501
commit
7ca4dfe09b
@ -242,8 +242,7 @@ func (h *ChatHandler) sendAzureMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新用户信息
|
// 更新用户信息
|
||||||
h.db.Model(&model.User{}).Where("id = ?", userVo.Id).
|
h.incUserTokenFee(userVo.Id, totalTokens)
|
||||||
UpdateColumn("total_tokens", gorm.Expr("total_tokens + ?", totalTokens))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存当前会话
|
// 保存当前会话
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gorm.io/gorm"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@ -184,8 +183,7 @@ func (h *ChatHandler) sendBaiduMessage(
|
|||||||
logger.Error("failed to save reply history message: ", res.Error)
|
logger.Error("failed to save reply history message: ", res.Error)
|
||||||
}
|
}
|
||||||
// 更新用户信息
|
// 更新用户信息
|
||||||
h.db.Model(&model.User{}).Where("id = ?", userVo.Id).
|
h.incUserTokenFee(userVo.Id, totalTokens)
|
||||||
UpdateColumn("total_tokens", gorm.Expr("total_tokens + ?", totalTokens))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存当前会话
|
// 保存当前会话
|
||||||
|
@ -187,8 +187,14 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if userVo.Calls < session.Model.Weight {
|
||||||
|
utils.ReplyMessage(ws, fmt.Sprintf("您当前剩余对话次数(%d)已不足以支付当前模型的单次对话需要消耗的对话额度(%d)!", userVo.Calls, session.Model.Weight))
|
||||||
|
utils.ReplyMessage(ws, ErrImg)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if userVo.Calls <= 0 && userVo.ChatConfig.ApiKeys[session.Model.Platform] == "" {
|
if userVo.Calls <= 0 && userVo.ChatConfig.ApiKeys[session.Model.Platform] == "" {
|
||||||
utils.ReplyMessage(ws, "您的对话次数已经用尽,请联系管理员或者点击左下角菜单加入众筹获得100次对话!")
|
utils.ReplyMessage(ws, "您的对话次数已经用尽,请联系管理员或者充值点卡继续对话!")
|
||||||
utils.ReplyMessage(ws, ErrImg)
|
utils.ReplyMessage(ws, ErrImg)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -477,3 +483,10 @@ func (h *ChatHandler) subUserCalls(userVo vo.User, session *types.ChatSession) {
|
|||||||
h.db.Model(&model.User{}).Where("id = ?", userVo.Id).UpdateColumn("calls", gorm.Expr("calls - ?", num))
|
h.db.Model(&model.User{}).Where("id = ?", userVo.Id).UpdateColumn("calls", gorm.Expr("calls - ?", num))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *ChatHandler) incUserTokenFee(userId uint, tokens int) {
|
||||||
|
h.db.Model(&model.User{}).Where("id = ?", userId).
|
||||||
|
UpdateColumn("total_tokens", gorm.Expr("total_tokens + ?", tokens))
|
||||||
|
h.db.Model(&model.User{}).Where("id = ?", userId).
|
||||||
|
UpdateColumn("tokens", gorm.Expr("tokens + ?", tokens))
|
||||||
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"gorm.io/gorm"
|
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -164,8 +163,7 @@ func (h *ChatHandler) sendChatGLMMessage(
|
|||||||
logger.Error("failed to save reply history message: ", res.Error)
|
logger.Error("failed to save reply history message: ", res.Error)
|
||||||
}
|
}
|
||||||
// 更新用户信息
|
// 更新用户信息
|
||||||
h.db.Model(&model.User{}).Where("id = ?", userVo.Id).
|
h.incUserTokenFee(userVo.Id, totalTokens)
|
||||||
UpdateColumn("total_tokens", gorm.Expr("total_tokens + ?", totalTokens))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存当前会话
|
// 保存当前会话
|
||||||
|
@ -241,8 +241,7 @@ func (h *ChatHandler) sendOpenAiMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新用户信息
|
// 更新用户信息
|
||||||
h.db.Model(&model.User{}).Where("id = ?", userVo.Id).
|
h.incUserTokenFee(userVo.Id, totalTokens)
|
||||||
UpdateColumn("total_tokens", gorm.Expr("total_tokens + ?", totalTokens))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存当前会话
|
// 保存当前会话
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"gorm.io/gorm"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -227,8 +226,7 @@ func (h *ChatHandler) sendXunFeiMessage(
|
|||||||
logger.Error("failed to save reply history message: ", res.Error)
|
logger.Error("failed to save reply history message: ", res.Error)
|
||||||
}
|
}
|
||||||
// 更新用户信息
|
// 更新用户信息
|
||||||
h.db.Model(&model.User{}).Where("id = ?", userVo.Id).
|
h.incUserTokenFee(userVo.Id, totalTokens)
|
||||||
UpdateColumn("total_tokens", gorm.Expr("total_tokens + ?", totalTokens))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存当前会话
|
// 保存当前会话
|
||||||
|
@ -5,55 +5,30 @@
|
|||||||
:close-on-click-modal="true"
|
:close-on-click-modal="true"
|
||||||
:before-close="close"
|
:before-close="close"
|
||||||
style="max-width: 600px"
|
style="max-width: 600px"
|
||||||
title="用户设置"
|
title="账户信息"
|
||||||
>
|
>
|
||||||
<div class="user-info" id="user-info">
|
<div class="user-info" id="user-info">
|
||||||
<el-form v-if="form.id" :model="form" label-width="150px">
|
<el-form v-if="user.id" :model="user" label-width="150px">
|
||||||
<el-form-item label="账户">
|
<el-form-item label="账户">
|
||||||
<span>{{ form.mobile }}</span>
|
<span>{{ user.mobile }}</span>
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="头像">
|
|
||||||
<el-upload
|
|
||||||
class="avatar-uploader"
|
|
||||||
:auto-upload="true"
|
|
||||||
:show-file-list="false"
|
|
||||||
:http-request="afterRead"
|
|
||||||
>
|
|
||||||
<el-avatar v-if="form.avatar" :src="form.avatar" shape="square" :size="100"/>
|
|
||||||
<el-icon v-else class="avatar-uploader-icon">
|
|
||||||
<Plus/>
|
|
||||||
</el-icon>
|
|
||||||
</el-upload>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="剩余对话次数">
|
<el-form-item label="剩余对话次数">
|
||||||
<el-tag>{{ form['calls'] }}</el-tag>
|
<el-tag>{{ user['calls'] }}</el-tag>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="剩余绘图次数">
|
<el-form-item label="剩余绘图次数">
|
||||||
<el-tag>{{ form['img_calls'] }}</el-tag>
|
<el-tag>{{ user['img_calls'] }}</el-tag>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="累计消耗 Tokens">
|
<el-form-item label="本月消耗电量">
|
||||||
<el-tag type="info">{{ form['total_tokens'] }}</el-tag>
|
<el-tag type="info">{{ user['tokens'] }}</el-tag>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="OpenAI API KEY">
|
<el-form-item label="累计消耗电量">
|
||||||
<el-input v-model="form.chat_config['api_keys']['OpenAI']"/>
|
<el-tag type="info">{{ user['total_tokens'] }}</el-tag>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Azure API KEY">
|
<el-form-item label="会员到期时间" v-if="user['expired_time'] > 0">
|
||||||
<el-input v-model="form['chat_config']['api_keys']['Azure']"/>
|
<el-tag type="danger">{{ dateFormat(user['expired_time']) }}</el-tag>
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="ChatGLM API KEY">
|
|
||||||
<el-input v-model="form['chat_config']['api_keys']['ChatGLM']"/>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template #footer>
|
|
||||||
<span class="dialog-footer">
|
|
||||||
<el-button @click="close">关闭</el-button>
|
|
||||||
<el-button type="primary" @click="save">
|
|
||||||
保存
|
|
||||||
</el-button>
|
|
||||||
</span>
|
|
||||||
</template>
|
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -63,6 +38,7 @@ import {httpGet, httpPost} from "@/utils/http";
|
|||||||
import {ElMessage} from "element-plus";
|
import {ElMessage} from "element-plus";
|
||||||
import {Plus} from "@element-plus/icons-vue";
|
import {Plus} from "@element-plus/icons-vue";
|
||||||
import Compressor from "compressorjs";
|
import Compressor from "compressorjs";
|
||||||
|
import {dateFormat} from "@/utils/libs";
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -74,7 +50,7 @@ const props = defineProps({
|
|||||||
const showDialog = computed(() => {
|
const showDialog = computed(() => {
|
||||||
return props.show
|
return props.show
|
||||||
})
|
})
|
||||||
const form = ref({
|
const user = ref({
|
||||||
username: '',
|
username: '',
|
||||||
nickname: '',
|
nickname: '',
|
||||||
avatar: '',
|
avatar: '',
|
||||||
@ -87,50 +63,15 @@ const form = ref({
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 获取最新用户信息
|
// 获取最新用户信息
|
||||||
httpGet('/api/user/profile').then(res => {
|
httpGet('/api/user/profile').then(res => {
|
||||||
form.value = res.data
|
user.value = res.data
|
||||||
form.value.chat_config.api_keys = res.data.chat_config.api_keys ?? {OpenAI: "", Azure: "", ChatGLM: ""}
|
user.value.chat_config.api_keys = res.data.chat_config.api_keys ?? {OpenAI: "", Azure: "", ChatGLM: ""}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
ElMessage.error("获取用户信息失败:" + e.message)
|
ElMessage.error("获取用户信息失败:" + e.message)
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
const afterRead = (file) => {
|
|
||||||
// console.log(file)
|
|
||||||
// 压缩图片并上传
|
|
||||||
new Compressor(file.file, {
|
|
||||||
quality: 0.6,
|
|
||||||
success(result) {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('file', result, result.name);
|
|
||||||
// 执行上传操作
|
|
||||||
httpPost('/api/upload', formData).then((res) => {
|
|
||||||
form.value.avatar = res.data
|
|
||||||
ElMessage.success({message: "上传成功", duration: 500})
|
|
||||||
}).catch((e) => {
|
|
||||||
ElMessage.error('上传失败:' + e.message)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
error(err) {
|
|
||||||
console.log(err.message);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const emits = defineEmits(['hide', 'update-user']);
|
const emits = defineEmits(['hide']);
|
||||||
const save = function () {
|
|
||||||
httpPost('/api/user/profile/update', form.value).then(() => {
|
|
||||||
ElMessage.success({
|
|
||||||
message: '更新成功',
|
|
||||||
duration: 500,
|
|
||||||
onClose: () => emits('hide', false)
|
|
||||||
})
|
|
||||||
// 更新用户数据
|
|
||||||
emits('update-user', {nickname: form.value['nickname'], avatar: form.value['avatar']});
|
|
||||||
}).catch((e) => {
|
|
||||||
ElMessage.error('更新失败:' + e.message)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const close = function () {
|
const close = function () {
|
||||||
emits('hide', false);
|
emits('hide', false);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
title="用户登录"
|
title="用户登录"
|
||||||
>
|
>
|
||||||
<div class="form">
|
<div class="form">
|
||||||
<el-form label-width="65px">
|
<el-form label-width="75px">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<template #label>
|
<template #label>
|
||||||
<div class="label">
|
<div class="label">
|
||||||
@ -20,7 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #default>
|
<template #default>
|
||||||
<el-input v-model="username" placeholder="手机号码"/>
|
<el-input v-model="username" size="large" placeholder="手机号码"/>
|
||||||
</template>
|
</template>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
@ -33,12 +33,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #default>
|
<template #default>
|
||||||
<el-input v-model="password" type="password" placeholder="密码"/>
|
<el-input v-model="password" type="password" size="large" placeholder="密码"/>
|
||||||
</template>
|
</template>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<div class="login-btn">
|
<div class="login-btn">
|
||||||
<el-button type="primary" @click="submit" round>登录</el-button>
|
<el-button type="primary" @click="submit" size="large" round>登录</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-form>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
@ -90,9 +90,17 @@ const close = function () {
|
|||||||
border-radius 20px
|
border-radius 20px
|
||||||
|
|
||||||
.label {
|
.label {
|
||||||
|
padding-top 3px
|
||||||
|
|
||||||
.el-icon {
|
.el-icon {
|
||||||
font-size 16px
|
position relative
|
||||||
|
font-size 20px
|
||||||
margin-right 6px
|
margin-right 6px
|
||||||
|
top 4px
|
||||||
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
font-size 16px
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,20 @@
|
|||||||
<el-form-item label="会员到期时间" v-if="user['expired_time'] > 0">
|
<el-form-item label="会员到期时间" v-if="user['expired_time'] > 0">
|
||||||
<el-tag type="danger">{{ dateFormat(user['expired_time']) }}</el-tag>
|
<el-tag type="danger">{{ dateFormat(user['expired_time']) }}</el-tag>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="OpenAI API KEY">
|
||||||
|
<el-input v-model="user.chat_config['api_keys']['OpenAI']"/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="Azure API KEY">
|
||||||
|
<el-input v-model="user['chat_config']['api_keys']['Azure']"/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="ChatGLM API KEY">
|
||||||
|
<el-input v-model="user['chat_config']['api_keys']['ChatGLM']"/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-row class="opt-line">
|
||||||
|
<el-button color="#47fff1" :dark="false" round @click="save">保存</el-button>
|
||||||
|
</el-row>
|
||||||
</el-form>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -43,6 +57,7 @@ import {ElMessage} from "element-plus";
|
|||||||
import {Plus} from "@element-plus/icons-vue";
|
import {Plus} from "@element-plus/icons-vue";
|
||||||
import Compressor from "compressorjs";
|
import Compressor from "compressorjs";
|
||||||
import {dateFormat} from "@/utils/libs";
|
import {dateFormat} from "@/utils/libs";
|
||||||
|
import {checkSession} from "@/action/session";
|
||||||
|
|
||||||
const user = ref({
|
const user = ref({
|
||||||
username: '',
|
username: '',
|
||||||
@ -55,6 +70,7 @@ const user = ref({
|
|||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
checkSession().then(() => {
|
||||||
// 获取最新用户信息
|
// 获取最新用户信息
|
||||||
httpGet('/api/user/profile').then(res => {
|
httpGet('/api/user/profile').then(res => {
|
||||||
user.value = res.data
|
user.value = res.data
|
||||||
@ -62,6 +78,9 @@ onMounted(() => {
|
|||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
ElMessage.error("获取用户信息失败:" + e.message)
|
ElMessage.error("获取用户信息失败:" + e.message)
|
||||||
});
|
});
|
||||||
|
}).catch(e => {
|
||||||
|
console.log(e)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const afterRead = (file) => {
|
const afterRead = (file) => {
|
||||||
@ -74,14 +93,7 @@ const afterRead = (file) => {
|
|||||||
// 执行上传操作
|
// 执行上传操作
|
||||||
httpPost('/api/upload', formData).then((res) => {
|
httpPost('/api/upload', formData).then((res) => {
|
||||||
user.value.avatar = res.data
|
user.value.avatar = res.data
|
||||||
httpPost('/api/user/profile/update', user.value).then(() => {
|
ElMessage.success({message: "上传成功", duration: 500})
|
||||||
ElMessage.success({
|
|
||||||
message: '更新成功',
|
|
||||||
duration: 500,
|
|
||||||
})
|
|
||||||
}).catch((e) => {
|
|
||||||
ElMessage.error('更新失败:' + e.message)
|
|
||||||
})
|
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
ElMessage.error('图片上传失败:' + e.message)
|
ElMessage.error('图片上传失败:' + e.message)
|
||||||
})
|
})
|
||||||
@ -91,6 +103,14 @@ const afterRead = (file) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const save = () => {
|
||||||
|
httpPost('/api/user/profile/update', user.value).then(() => {
|
||||||
|
ElMessage.success({message: '更新成功', duration: 500})
|
||||||
|
}).catch((e) => {
|
||||||
|
ElMessage.error('更新失败:' + e.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="stylus" scoped>
|
<style lang="stylus" scoped>
|
||||||
@ -101,5 +121,13 @@ const afterRead = (file) => {
|
|||||||
justify-content center
|
justify-content center
|
||||||
margin-bottom 10px
|
margin-bottom 10px
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.opt-line {
|
||||||
|
padding-top 20px
|
||||||
|
|
||||||
|
.el-button {
|
||||||
|
width 100%
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
@ -32,7 +32,7 @@ import {
|
|||||||
TextEllipsis,
|
TextEllipsis,
|
||||||
Uploader
|
Uploader
|
||||||
} from "vant";
|
} from "vant";
|
||||||
import router from "@/router";
|
import {router} from "@/router";
|
||||||
import 'v3-waterfall/dist/style.css'
|
import 'v3-waterfall/dist/style.css'
|
||||||
import V3waterfall from "v3-waterfall";
|
import V3waterfall from "v3-waterfall";
|
||||||
|
|
||||||
|
@ -226,12 +226,14 @@ const router = createRouter({
|
|||||||
routes: routes,
|
routes: routes,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let prevRoute = null
|
||||||
// dynamic change the title when router change
|
// dynamic change the title when router change
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
if (to.meta.title) {
|
if (to.meta.title) {
|
||||||
document.title = `${to.meta.title} | ${process.env.VUE_APP_TITLE}`
|
document.title = `${to.meta.title} | ${process.env.VUE_APP_TITLE}`
|
||||||
}
|
}
|
||||||
|
prevRoute = from
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
export default router;
|
export {router, prevRoute};
|
@ -40,7 +40,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {nextTick, onMounted, ref} from "vue"
|
import {onMounted, ref} from "vue"
|
||||||
import {ElMessage} from "element-plus";
|
import {ElMessage} from "element-plus";
|
||||||
import {httpGet, httpPost} from "@/utils/http";
|
import {httpGet, httpPost} from "@/utils/http";
|
||||||
import ItemList from "@/components/ItemList.vue";
|
import ItemList from "@/components/ItemList.vue";
|
||||||
@ -48,7 +48,6 @@ import {Delete, Plus} from "@element-plus/icons-vue";
|
|||||||
import LoginDialog from "@/components/LoginDialog.vue";
|
import LoginDialog from "@/components/LoginDialog.vue";
|
||||||
import {checkSession} from "@/action/session";
|
import {checkSession} from "@/action/session";
|
||||||
import {arrayContains, removeArrayItem, substr} from "@/utils/libs";
|
import {arrayContains, removeArrayItem, substr} from "@/utils/libs";
|
||||||
import router from "@/router";
|
|
||||||
|
|
||||||
const listBoxHeight = window.innerHeight - 97
|
const listBoxHeight = window.innerHeight - 97
|
||||||
const list = ref([])
|
const list = ref([])
|
||||||
@ -71,8 +70,8 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const getRoles = () => {
|
const getRoles = () => {
|
||||||
checkSession().then(user => {
|
|
||||||
showLoginDialog.value = false
|
showLoginDialog.value = false
|
||||||
|
checkSession().then(user => {
|
||||||
roles.value = user.chat_roles
|
roles.value = user.chat_roles
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
})
|
})
|
||||||
|
@ -52,33 +52,7 @@
|
|||||||
<el-icon>
|
<el-icon>
|
||||||
<Tools/>
|
<Tools/>
|
||||||
</el-icon>
|
</el-icon>
|
||||||
<span>聊天设置</span>
|
<span>账户信息</span>
|
||||||
</el-dropdown-item>
|
|
||||||
|
|
||||||
<el-dropdown-item @click="showPasswordDialog=true">
|
|
||||||
<i class="iconfont icon-password"></i>
|
|
||||||
<span>修改密码</span>
|
|
||||||
</el-dropdown-item>
|
|
||||||
|
|
||||||
<el-dropdown-item @click="showBindMobileDialog = true">
|
|
||||||
<el-icon>
|
|
||||||
<Iphone/>
|
|
||||||
</el-icon>
|
|
||||||
<span>绑定手机号</span>
|
|
||||||
</el-dropdown-item>
|
|
||||||
|
|
||||||
<el-dropdown-item @click="showRewardDialog = true" v-if="enableReward">
|
|
||||||
<el-icon>
|
|
||||||
<Present/>
|
|
||||||
</el-icon>
|
|
||||||
<span>加入众筹</span>
|
|
||||||
</el-dropdown-item>
|
|
||||||
|
|
||||||
<el-dropdown-item @click="showRewardVerifyDialog = true" v-if="enableReward">
|
|
||||||
<el-icon>
|
|
||||||
<Checked/>
|
|
||||||
</el-icon>
|
|
||||||
<span>众筹核销</span>
|
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
|
|
||||||
<el-dropdown-item @click="clearAllChats">
|
<el-dropdown-item @click="clearAllChats">
|
||||||
@ -222,30 +196,6 @@
|
|||||||
|
|
||||||
<config-dialog v-if="isLogin" :show="showConfigDialog" :models="models" @hide="showConfigDialog = false"
|
<config-dialog v-if="isLogin" :show="showConfigDialog" :models="models" @hide="showConfigDialog = false"
|
||||||
@update-user="updateUser"/>
|
@update-user="updateUser"/>
|
||||||
<password-dialog v-if="isLogin" :show="showPasswordDialog" @hide="showPasswordDialog = false"
|
|
||||||
@logout="logout"/>
|
|
||||||
|
|
||||||
<bind-mobile v-if="isLogin" :show="showBindMobileDialog" :mobile="loginUser.mobile"
|
|
||||||
@hide="showBindMobileDialog = false"/>
|
|
||||||
|
|
||||||
<reward-verify v-if="isLogin" :show="showRewardVerifyDialog" @hide="showRewardVerifyDialog = false"/>
|
|
||||||
|
|
||||||
<el-dialog
|
|
||||||
v-model="showRewardDialog"
|
|
||||||
:show-close="true"
|
|
||||||
width="400px"
|
|
||||||
title="参与众筹"
|
|
||||||
>
|
|
||||||
<el-alert type="info" :closable="false">
|
|
||||||
<div style="font-size: 14px">您好,众筹 9.9元,就可以兑换 100 次对话,以此来覆盖我们的 OpenAI
|
|
||||||
账单和服务器的费用。<strong
|
|
||||||
style="color: #f56c6c">由于本人没有开通微信支付,付款后请凭借转账单号进入核销【众筹核销】菜单手动核销。</strong>
|
|
||||||
</div>
|
|
||||||
</el-alert>
|
|
||||||
<div style="text-align: center;padding-top: 10px;">
|
|
||||||
<el-image v-if="enableReward" :src="rewardImg"/>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@ -257,13 +207,10 @@ import ChatReply from "@/components/ChatReply.vue";
|
|||||||
import {
|
import {
|
||||||
ArrowDown,
|
ArrowDown,
|
||||||
Check,
|
Check,
|
||||||
Checked,
|
|
||||||
Close,
|
Close,
|
||||||
Delete,
|
Delete,
|
||||||
Edit,
|
Edit,
|
||||||
Iphone,
|
|
||||||
Plus,
|
Plus,
|
||||||
Present,
|
|
||||||
Promotion,
|
Promotion,
|
||||||
RefreshRight,
|
RefreshRight,
|
||||||
Search,
|
Search,
|
||||||
@ -279,16 +226,11 @@ import {httpGet, httpPost} from "@/utils/http";
|
|||||||
import {useRouter} from "vue-router";
|
import {useRouter} from "vue-router";
|
||||||
import Clipboard from "clipboard";
|
import Clipboard from "clipboard";
|
||||||
import ConfigDialog from "@/components/ConfigDialog.vue";
|
import ConfigDialog from "@/components/ConfigDialog.vue";
|
||||||
import PasswordDialog from "@/components/PasswordDialog.vue";
|
|
||||||
import {checkSession} from "@/action/session";
|
import {checkSession} from "@/action/session";
|
||||||
import BindMobile from "@/components/BindMobile.vue";
|
|
||||||
import RewardVerify from "@/components/RewardVerify.vue";
|
|
||||||
import Welcome from "@/components/Welcome.vue";
|
import Welcome from "@/components/Welcome.vue";
|
||||||
import ChatMidJourney from "@/components/ChatMidJourney.vue";
|
import ChatMidJourney from "@/components/ChatMidJourney.vue";
|
||||||
|
|
||||||
const title = ref('ChatGPT-智能助手');
|
const title = ref('ChatGPT-智能助手');
|
||||||
const enableReward = ref(false) // 是否启用众筹功能
|
|
||||||
const rewardImg = ref('/images/reward.png')
|
|
||||||
const models = ref([])
|
const models = ref([])
|
||||||
const modelID = ref(0)
|
const modelID = ref(0)
|
||||||
const chatData = ref([]);
|
const chatData = ref([]);
|
||||||
@ -305,10 +247,6 @@ const roleId = ref(0)
|
|||||||
const newChatItem = ref(null);
|
const newChatItem = ref(null);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const showConfigDialog = ref(false);
|
const showConfigDialog = ref(false);
|
||||||
const showPasswordDialog = ref(false);
|
|
||||||
const showBindMobileDialog = ref(false);
|
|
||||||
const showRewardDialog = ref(false);
|
|
||||||
const showRewardVerifyDialog = ref(false);
|
|
||||||
const isLogin = ref(false)
|
const isLogin = ref(false)
|
||||||
const showHello = ref(true)
|
const showHello = ref(true)
|
||||||
const textInput = ref(null)
|
const textInput = ref(null)
|
||||||
@ -360,8 +298,6 @@ onMounted(() => {
|
|||||||
|
|
||||||
httpGet("/api/admin/config/get?key=system").then(res => {
|
httpGet("/api/admin/config/get?key=system").then(res => {
|
||||||
title.value = res.data.title
|
title.value = res.data.title
|
||||||
rewardImg.value = res.data.reward_img
|
|
||||||
enableReward.value = res.data.enabled_reward
|
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
ElMessage.error("获取系统配置失败:" + e.message)
|
ElMessage.error("获取系统配置失败:" + e.message)
|
||||||
})
|
})
|
||||||
@ -855,11 +791,6 @@ const searchChat = function () {
|
|||||||
chatList.value = items;
|
chatList.value = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateUser = function (data) {
|
|
||||||
loginUser.value.avatar = data.avatar;
|
|
||||||
loginUser.value.nickname = data.nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 导出会话
|
// 导出会话
|
||||||
const exportChat = () => {
|
const exportChat = () => {
|
||||||
if (!activeChat.value['chat_id']) {
|
if (!activeChat.value['chat_id']) {
|
||||||
|
@ -58,6 +58,7 @@ import {isMobile} from "@/utils/libs";
|
|||||||
import {checkSession} from "@/action/session";
|
import {checkSession} from "@/action/session";
|
||||||
import {setUserToken} from "@/store/session";
|
import {setUserToken} from "@/store/session";
|
||||||
import {validateMobile} from "@/utils/validate";
|
import {validateMobile} from "@/utils/validate";
|
||||||
|
import {prevRoute} from "@/router";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const title = ref('ChatGPT-PLUS 用户登录');
|
const title = ref('ChatGPT-PLUS 用户登录');
|
||||||
@ -91,11 +92,16 @@ const login = function () {
|
|||||||
|
|
||||||
httpPost('/api/user/login', {username: username.value.trim(), password: password.value.trim()}).then((res) => {
|
httpPost('/api/user/login', {username: username.value.trim(), password: password.value.trim()}).then((res) => {
|
||||||
setUserToken(res.data)
|
setUserToken(res.data)
|
||||||
|
if (prevRoute.path === '') {
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
router.push('/mobile')
|
router.push('/mobile')
|
||||||
} else {
|
} else {
|
||||||
router.push('/chat')
|
router.push('/chat')
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
router.push(prevRoute.path)
|
||||||
|
}
|
||||||
|
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
ElMessage.error('登录失败,' + e.message)
|
ElMessage.error('登录失败,' + e.message)
|
||||||
})
|
})
|
||||||
|
@ -7,6 +7,21 @@
|
|||||||
|
|
||||||
<div class="user-profile">
|
<div class="user-profile">
|
||||||
<user-profile/>
|
<user-profile/>
|
||||||
|
|
||||||
|
<el-row class="user-opt" :gutter="20">
|
||||||
|
<el-col :span="12">
|
||||||
|
<el-button type="primary">修改密码</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="12">
|
||||||
|
<el-button type="primary">绑定手机号</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="12">
|
||||||
|
<el-button type="primary">加入众筹</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="12">
|
||||||
|
<el-button type="primary">众筹核销</el-button>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="product-box">
|
<div class="product-box">
|
||||||
@ -49,6 +64,31 @@
|
|||||||
|
|
||||||
<login-dialog :show="showLoginDialog" @hide="showLoginDialog = false"/>
|
<login-dialog :show="showLoginDialog" @hide="showLoginDialog = false"/>
|
||||||
|
|
||||||
|
<password-dialog v-if="isLogin" :show="showPasswordDialog" @hide="showPasswordDialog = false"
|
||||||
|
@logout="logout"/>
|
||||||
|
|
||||||
|
<bind-mobile v-if="isLogin" :show="showBindMobileDialog" :mobile="loginUser.mobile"
|
||||||
|
@hide="showBindMobileDialog = false"/>
|
||||||
|
|
||||||
|
<reward-verify v-if="isLogin" :show="showRewardVerifyDialog" @hide="showRewardVerifyDialog = false"/>
|
||||||
|
|
||||||
|
<el-dialog
|
||||||
|
v-model="showRewardDialog"
|
||||||
|
:show-close="true"
|
||||||
|
width="400px"
|
||||||
|
title="参与众筹"
|
||||||
|
>
|
||||||
|
<el-alert type="info" :closable="false">
|
||||||
|
<div style="font-size: 14px">您好,众筹 9.9元,就可以兑换 100 次对话,以此来覆盖我们的 OpenAI
|
||||||
|
账单和服务器的费用。<strong
|
||||||
|
style="color: #f56c6c">由于本人没有开通微信支付,付款后请凭借转账单号进入核销【众筹核销】菜单手动核销。</strong>
|
||||||
|
</div>
|
||||||
|
</el-alert>
|
||||||
|
<div style="text-align: center;padding-top: 10px;">
|
||||||
|
<el-image v-if="enableReward" :src="rewardImg"/>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
<el-dialog
|
<el-dialog
|
||||||
v-model="showPayDialog"
|
v-model="showPayDialog"
|
||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
@ -78,16 +118,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {nextTick, onMounted, ref} from "vue"
|
import {onMounted, ref} from "vue"
|
||||||
import {ElMessage} from "element-plus";
|
import {ElMessage} from "element-plus";
|
||||||
import {httpGet, httpPost} from "@/utils/http";
|
import {httpGet, httpPost} from "@/utils/http";
|
||||||
import ItemList from "@/components/ItemList.vue";
|
import ItemList from "@/components/ItemList.vue";
|
||||||
import {Delete, InfoFilled, Plus, SuccessFilled} from "@element-plus/icons-vue";
|
import {InfoFilled, SuccessFilled} from "@element-plus/icons-vue";
|
||||||
import LoginDialog from "@/components/LoginDialog.vue";
|
import LoginDialog from "@/components/LoginDialog.vue";
|
||||||
import {checkSession} from "@/action/session";
|
import {checkSession} from "@/action/session";
|
||||||
import {arrayContains, removeArrayItem, substr} from "@/utils/libs";
|
|
||||||
import router from "@/router";
|
|
||||||
import UserProfile from "@/components/UserProfile.vue";
|
import UserProfile from "@/components/UserProfile.vue";
|
||||||
|
import PasswordDialog from "@/components/PasswordDialog.vue";
|
||||||
|
import BindMobile from "@/components/BindMobile.vue";
|
||||||
|
import RewardVerify from "@/components/RewardVerify.vue";
|
||||||
|
import {useRouter} from "vue-router";
|
||||||
|
|
||||||
const listBoxHeight = window.innerHeight - 97
|
const listBoxHeight = window.innerHeight - 97
|
||||||
const list = ref([])
|
const list = ref([])
|
||||||
@ -95,33 +137,52 @@ const showLoginDialog = ref(false)
|
|||||||
const showPayDialog = ref(false)
|
const showPayDialog = ref(false)
|
||||||
const elements = ref(null)
|
const elements = ref(null)
|
||||||
const vipImg = ref("/images/vip.png")
|
const vipImg = ref("/images/vip.png")
|
||||||
|
const enableReward = ref(false) // 是否启用众筹功能
|
||||||
|
const rewardImg = ref('/images/reward.png')
|
||||||
const qrcode = ref("")
|
const qrcode = ref("")
|
||||||
const amount = ref(0)
|
const showPasswordDialog = ref(false);
|
||||||
const discount = ref(0)
|
const showBindMobileDialog = ref(false);
|
||||||
|
const showRewardDialog = ref(false);
|
||||||
|
const showRewardVerifyDialog = ref(false);
|
||||||
const text = ref("")
|
const text = ref("")
|
||||||
|
const user = ref(null)
|
||||||
|
const isLogin = ref(false)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
checkSession().then(_user => {
|
||||||
|
user.value = _user
|
||||||
|
isLogin.value = true
|
||||||
httpGet("/api/product/list").then((res) => {
|
httpGet("/api/product/list").then((res) => {
|
||||||
list.value = res.data
|
list.value = res.data
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
ElMessage.error("获取产品套餐失败:" + e.message)
|
ElMessage.error("获取产品套餐失败:" + e.message)
|
||||||
})
|
})
|
||||||
|
}).catch(() => {
|
||||||
|
router.push("/login")
|
||||||
|
})
|
||||||
|
|
||||||
|
httpGet("/api/admin/config/get?key=system").then(res => {
|
||||||
|
rewardImg.value = res.data['reward_img']
|
||||||
|
enableReward.value = res.data['enabled_reward']
|
||||||
|
}).catch(e => {
|
||||||
|
ElMessage.error("获取系统配置失败:" + e.message)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const orderPay = (row) => {
|
const orderPay = (row) => {
|
||||||
checkSession().then(user => {
|
if (!user.value.id) {
|
||||||
console.log(row)
|
showLoginDialog.value = true
|
||||||
httpPost("/api/payment/alipay/qrcode", {product_id: row.id, user_id: user.id}).then(res => {
|
return
|
||||||
console.log(res)
|
}
|
||||||
|
httpPost("/api/payment/alipay/qrcode", {product_id: row.id, user_id: user.value.id}).then(res => {
|
||||||
showPayDialog.value = true
|
showPayDialog.value = true
|
||||||
qrcode.value = res.data['image']
|
qrcode.value = res.data['image']
|
||||||
queryOrder(res.data['order_no'])
|
queryOrder(res.data['order_no'])
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
ElMessage.error("生成支付订单失败:" + e.message)
|
ElMessage.error("生成支付订单失败:" + e.message)
|
||||||
})
|
})
|
||||||
}).catch(e => {
|
|
||||||
console.log(e)
|
|
||||||
showLoginDialog.value = true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryOrder = (orderNo) => {
|
const queryOrder = (orderNo) => {
|
||||||
@ -210,7 +271,18 @@ const queryOrder = (orderNo) => {
|
|||||||
color #ffffff
|
color #ffffff
|
||||||
justify-content start
|
justify-content start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.user-opt {
|
||||||
|
.el-col {
|
||||||
|
padding 10px
|
||||||
|
|
||||||
|
.el-button {
|
||||||
|
width 100%
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.product-box {
|
.product-box {
|
||||||
padding 0 10px
|
padding 0 10px
|
||||||
|
@ -78,7 +78,7 @@ import {ref} from "vue";
|
|||||||
import {httpGet, httpPost} from "@/utils/http";
|
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 {setChatConfig} from "@/store/chat";
|
import {setChatConfig} from "@/store/chat";
|
||||||
import {removeArrayItem} from "@/utils/libs";
|
import {removeArrayItem} from "@/utils/libs";
|
||||||
import BindMobile from "@/components/mobile/BindMobile.vue";
|
import BindMobile from "@/components/mobile/BindMobile.vue";
|
||||||
|
Loading…
Reference in New Issue
Block a user