allow user to use chat role directly, no need to add to workspace

This commit is contained in:
RockYang 2024-07-16 18:28:08 +08:00
parent 024f00b73c
commit 82fe9c3596
7 changed files with 51 additions and 56 deletions

View File

@ -29,45 +29,32 @@ func NewChatRoleHandler(app *core.AppServer, db *gorm.DB) *ChatRoleHandler {
// List 获取用户聊天应用列表
func (h *ChatRoleHandler) List(c *gin.Context) {
all := h.GetBool(c, "all")
id := h.GetInt(c, "id", 0)
userId := h.GetLoginUserId(c)
var roles []model.ChatRole
var roleVos = make([]vo.ChatRole, 0)
query := h.DB.Where("enable", true)
if userId > 0 {
var user model.User
h.DB.First(&user, userId)
var roleKeys []string
err := utils.JsonDecode(user.ChatRoles, &roleKeys)
if err != nil {
resp.ERROR(c, "角色解析失败!")
return
}
query = query.Where("marker IN ?", roleKeys)
}
if id > 0 {
query = query.Or("id", id)
}
res := h.DB.Where("enable", true).Order("sort_num ASC").Find(&roles)
if res.Error != nil {
resp.SUCCESS(c, roleVos)
return
}
// 获取所有角色
if userId == 0 || all {
// 转成 vo
var roleVos = make([]vo.ChatRole, 0)
for _, r := range roles {
var v vo.ChatRole
err := utils.CopyObject(r, &v)
if err == nil {
v.Id = r.Id
roleVos = append(roleVos, v)
}
}
resp.SUCCESS(c, roleVos)
return
}
var user model.User
h.DB.First(&user, userId)
var roleKeys []string
err := utils.JsonDecode(user.ChatRoles, &roleKeys)
if err != nil {
resp.ERROR(c, "角色解析失败!")
resp.ERROR(c, res.Error.Error())
return
}
var roleVos = make([]vo.ChatRole, 0)
for _, r := range roles {
if !utils.Contains(roleKeys, r.Key) {
continue
}
var v vo.ChatRole
err := utils.CopyObject(r, &v)
if err == nil {

View File

@ -15,18 +15,13 @@
<div class="info-text">{{ scope.item.hello_msg }}</div>
</div>
<div class="btn">
<div v-if="hasRole(scope.item.key)">
<el-button size="small" color="#21aa93" @click="useRole(scope.item)">使用</el-button>
<el-button size="small" color="#21aa93" @click="useRole(scope.item)">使用</el-button>
<el-tooltip effect="light" content="从工作区移除" placement="top" v-if="hasRole(scope.item.key)">
<el-button size="small" type="danger" @click="updateRole(scope.item,'remove')">移除</el-button>
</div>
<el-button v-else size="small"
style="--el-color-primary:#009999"
@click="updateRole(scope.item, 'add')">
<el-icon>
<Plus/>
</el-icon>
<span>添加应用</span>
</el-button>
</el-tooltip>
<el-tooltip effect="light" content="添加到工作区" placement="top" v-else>
<el-button size="small" style="--el-color-primary:#009999" @click="updateRole(scope.item, 'add')">添加</el-button>
</el-tooltip>
</div>
</div>
@ -77,7 +72,7 @@ const roles = ref([])
const store = useSharedStore();
onMounted(() => {
httpGet("/api/role/list?all=true").then((res) => {
httpGet("/api/role/list").then((res) => {
const items = res.data
// hello message
for (let i = 0; i < items.length; i++) {

View File

@ -316,18 +316,17 @@ const initData = () => {
chatList.value = res.data;
allChats.value = res.data;
}
if (router.currentRoute.value.query.role_id) {
roleId.value = parseInt(router.currentRoute.value.query.role_id)
}
//
httpGet('/api/model/list').then(res => {
models.value = res.data
modelID.value = models.value[0].id
//
httpGet(`/api/role/list`).then((res) => {
httpGet(`/api/role/list`,{id:roleId.value}).then((res) => {
roles.value = res.data;
if (router.currentRoute.value.query.role_id) {
roleId.value = parseInt(router.currentRoute.value.query.role_id)
} else {
if (!roleId.value) {
roleId.value = roles.value[0]['id']
}
@ -354,7 +353,7 @@ const initData = () => {
})
//
httpGet('/api/model/list').then(res => {
httpGet('/api/model/list',{id:roleId.value}).then(res => {
models.value = res.data
modelID.value = models.value[0].id
}).catch(e => {

View File

@ -166,6 +166,12 @@ watch(() => store.showLoginDialog, (newValue) => {
show.value = newValue
});
//
router.beforeEach((to, from, next) => {
curPath.value = to.path
next();
});
if (curPath.value === "/external") {
curPath.value = router.currentRoute.value.query.url
}

View File

@ -105,7 +105,7 @@ checkSession().then((user) => {
loginUser.value = user
isLogin.value = true
//
httpGet(`/api/role/list?user_id=${user.id}`).then((res) => {
httpGet(`/api/role/list`).then((res) => {
if (res.data) {
const items = res.data
for (let i = 0; i < items.length; i++) {

View File

@ -109,7 +109,7 @@ onMounted(() => {
})
const fetchApps = () => {
httpGet("/api/role/list?all=true").then((res) => {
httpGet("/api/role/list").then((res) => {
const items = res.data
// hello message
for (let i = 0; i < items.length; i++) {

View File

@ -407,8 +407,16 @@ const connect = () => {
_socket.addEventListener('message', event => {
if (event.data instanceof Blob) {
fetchRunningJobs()
fetchFinishJobs(1)
const reader = new FileReader();
reader.readAsText(event.data, "UTF-8")
reader.onload = () => {
const message = String(reader.result)
if (message === "FINISH" || message === "FAIL") {
page.value = 1
fetchFinishJobs(1)
}
fetchRunningJobs()
}
}
});
@ -456,7 +464,7 @@ const fetchFinishJobs = (page) => {
httpGet(`/api/mj/jobs?finish=1&page=${page}&page_size=${pageSize.value}`).then(res => {
const jobs = res.data
for (let i = 0; i < jobs.length; i++) {
if (jobs[i].progress === -1) {
if (jobs[i].progress === 101) {
showNotify({
message: `任务ID${jobs[i]['task_id']} 原因:${jobs[i]['err_msg']}`,
type: 'danger',
@ -479,7 +487,7 @@ const fetchFinishJobs = (page) => {
}
}
if (jobs[i].type === 'image' || jobs[i].type === 'variation') {
if ((jobs[i].type === 'image' || jobs[i].type === 'variation') && jobs[i].progress === 100){
jobs[i]['can_opt'] = true
}
}