Thu Jul 6 08:14:00 UTC 2023 inscode

上级 714e9e5a
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
<t-image class="rounded-lg" v-if="config.robot_img" :src="config.robot_img" fit="cover" <t-image class="rounded-lg" v-if="config.robot_img" :src="config.robot_img" fit="cover"
:style="{ width: '40px', height: '40px' }"></t-image> :style="{ width: '40px', height: '40px' }"></t-image>
<div class="bg-slate-50 text-gray-700 p-4 mx-2 w-fit max-w-2xl 2xl:max-w-4xl rounded-lg text-wrapper"> <div class="bg-slate-50 text-gray-700 p-4 mx-2 w-fit max-w-2xl 2xl:max-w-4xl rounded-lg text-wrapper">
{{ item.img }}
<template v-if="item?.viewMode??'chat' === 'image'"> <template v-if="item?.viewMode??'chat' === 'image'">
<img v-if="item.img" :src="item.img"/> <img v-if="item.img" :src="item.img"/>
<img v-else src="/loading.gif" class="max-w-[512px]"/> <img v-else src="/loading.gif" class="max-w-[512px]"/>
...@@ -137,6 +137,7 @@ ...@@ -137,6 +137,7 @@
import OpenAI from './js/openai.js' import OpenAI from './js/openai.js'
import Config from './js/config.js' import Config from './js/config.js'
import SDApi from './js/sd.js' import SDApi from './js/sd.js'
import StorageApi from './js/storage.js'
// import MarkdownItVue from 'markdown-it-vue' // import MarkdownItVue from 'markdown-it-vue'
// import 'markdown-it-vue/dist/markdown-it-vue.css' // import 'markdown-it-vue/dist/markdown-it-vue.css'
...@@ -156,7 +157,7 @@ export default { ...@@ -156,7 +157,7 @@ export default {
userAvatarList: [], userAvatarList: [],
robotAvatarList: [], robotAvatarList: [],
mode: 'draw', mode: 'draw',
modeImage: 'chart-bubble', modeImage: 'image', // image chat chart-bubble
message: [ message: [
// {"user": "User", "message": "创建一个用户表,要求分区"}, // {"user": "User", "message": "创建一个用户表,要求分区"},
// {"user": "AI", "message": "在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:"}, // {"user": "AI", "message": "在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:"},
...@@ -183,9 +184,13 @@ export default { ...@@ -183,9 +184,13 @@ export default {
height: 512, height: 512,
steps: 20, steps: 20,
sampler: 'DPM++ SDE Karras', sampler: 'DPM++ SDE Karras',
showMoreSetting: false, showMoreSetting: true,
default_prompt: '1girl, (ulzzang-6500:0.7), kpop idol, yae miko, detached sleeves, bare shoulders, pink hair, long hair, cleavage,japanese clothes,breast,best quality, (painting:1.5), (hair ornament:1.35), jewelry, purple eyes, earrings, breasts, torii, cherry blossoms, lantern light, depth of field, detailed face, face focus, ribbon_trim, (looking at viewer:1.25), nontraditional miko, shiny skin, long sleeves, smile, thick lips, game cg, east asian architecture, (blurry background:1.2), sitting, upper body <lora:YaeMiko_Test:0.45>,<lora:mix4:0.5>', default_prompt: '1girl, (ulzzang-6500:0.7), kpop idol, yae miko, detached sleeves, bare shoulders, pink hair, long hair, cleavage,japanese clothes,breast,best quality, (painting:1.5), (hair ornament:1.35), jewelry, purple eyes, earrings, breasts, torii, cherry blossoms, lantern light, depth of field, detailed face, face focus, ribbon_trim, (looking at viewer:1.25), nontraditional miko, shiny skin, long sleeves, smile, thick lips, game cg, east asian architecture, (blurry background:1.2), sitting, upper body <lora:YaeMiko_Test:0.45>,<lora:mix4:0.5>',
negative_prompt: 'bright lantern, brightness, (nipples:1.2), pussy, EasyNegative, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans,extra fingers, fewer fingers, strange fingers, bad hand, bare thighs,hand,bad finger', negative_prompt: 'bright lantern, brightness, (nipples:1.2), pussy, EasyNegative, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans,extra fingers, fewer fingers, strange fingers, bad hand, bare thighs,hand,bad finger',
history: {
name: 'ai',
key: 'history',
},
} }
}, },
methods: { methods: {
...@@ -391,14 +396,17 @@ export default { ...@@ -391,14 +396,17 @@ export default {
} }
}, },
recoveryHistory() { recoveryHistory() {
const cacheKey = 'history_' + this.id const cacheKey = this.history.key
const data = localStorage.getItem(cacheKey)
if (data) { StorageApi.get(this.history.name, cacheKey).then(data => {
this.message = JSON.parse(data) debugger
} if (data && data.data) {
this.message = JSON.parse(data.data)
}
})
}, },
saveHistory() { saveHistory() {
const cacheKey = 'history_' + this.id const cacheKey = this.history.key
if (this.message.length > this.maxHistory) { if (this.message.length > this.maxHistory) {
const tmpHistory = [] const tmpHistory = []
const start = this.message.length - this.maxHistory const start = this.message.length - this.maxHistory
...@@ -406,9 +414,9 @@ export default { ...@@ -406,9 +414,9 @@ export default {
for (let id = start; id < end; id++) { for (let id = start; id < end; id++) {
tmpHistory.push(this.message[id]) tmpHistory.push(this.message[id])
} }
localStorage.setItem(cacheKey, JSON.stringify(tmpHistory)) StorageApi.set(this.history.name, cacheKey, JSON.stringify(tmpHistory))
} else { } else {
localStorage.setItem(cacheKey, JSON.stringify(this.message)) StorageApi.set(this.history.name, cacheKey, JSON.stringify(this.message))
} }
}, },
...@@ -445,7 +453,9 @@ export default { ...@@ -445,7 +453,9 @@ export default {
}, },
mounted() { mounted() {
this.id = this.$route?.params?.id this.id = this.$route?.params?.id
this.recoveryHistory() StorageApi.init(this.history.name).then(res => {
this.recoveryHistory()
})
this.getAppInfo() this.getAppInfo()
// this.getAvatar() // this.getAvatar()
if (this.mode === 'draw') { if (this.mode === 'draw') {
......
let db = null
const defaultTableName = 'history'
export default {
init(tableName = defaultTableName) {
let request = window.indexedDB.open('ai-draw', '1')
return new Promise((resolve, reject) => {
// 数据库操作过程中出错,则错误回调被触发
request.onerror = (event) => {
console.log("db init报错" + event)
reject()
}
request.onsuccess = (event) => {
db = event.target.result
console.log("db init成功")
resolve()
}
request.onupgradeneeded = (event) => {
db = event.target.result
let objectStore = db.createObjectStore(tableName, { keyPath: 'id' })
objectStore.createIndex('key', 'key', { unique: true })
console.log("db onupgradeneeded 成功")
resolve()
}
})
},
isConnected(tableName = defaultTableName){
return db != null
},
set(tableName = defaultTableName, key, val, id = 100){
let request = db.transaction(tableName, 'readwrite')
.objectStore(tableName)
.add({
id: id,
key: key,
data: val
})
return new Promise((resolve, reject) => {
request.onsuccess = (event) => {
console.info('添加成功', event)
resolve(event)
}
request.onerror = (event) => {
console.info('添加失败')
reject(event)
}
})
},
getAll(tableName = defaultTableName){
let request = db.transaction(tableName, 'readwrite')
.objectStore(tableName)
.index('key')
.getAll()
console.info("开水获取全部")
return new Promise((resolve, reject) => {
request.onsuccess = (event) => {
console.info('获取成功')
resolve(request.result)
}
request.onerror = (event) => {
console.info('获取失败')
reject(event)
}
})
},
get(tableName = defaultTableName, key){
let request = db.transaction(tableName, 'readwrite')
.objectStore(tableName)
.index('key')
.get(key)
console.info("获取")
return new Promise((resolve, reject) => {
request.onsuccess = (event) => {
console.info('获取成功')
resolve(request.result)
}
request.onerror = (event) => {
console.info('获取失败')
reject(event)
}
})
},
del(tableName = defaultTableName, id = 100){
let request = db.transaction(tableName, 'readwrite')
.objectStore(tableName)
.delete(id)
console.info("开始删除")
return new Promise((resolve, reject) => {
request.onsuccess = (event) => {
console.info('删除成功')
resolve(request.result)
}
request.onerror = (event) => {
console.info('删除失败')
reject(event)
}
})
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册