Update input box height (#25)
This commit is contained in:
1 parent
4b7b13276e
commit
704da3e128
1 file changed
+44
-18
@@ -1,9 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div class="input-box">
|
||||||
<el-upload
|
<el-upload
|
||||||
v-if="canUpload"
|
|
||||||
v-model:file-list="fileList"
|
v-model:file-list="fileList"
|
||||||
:class="{
|
:class="{
|
||||||
upload: true
|
upload: true,
|
||||||
|
disabled: !canUpload
|
||||||
}"
|
}"
|
||||||
:disabled="!canUpload"
|
:disabled="!canUpload"
|
||||||
name="file"
|
name="file"
|
||||||
@@ -21,33 +22,35 @@
|
|||||||
</span>
|
</span>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
<div class="input-box">
|
|
||||||
<span
|
<span
|
||||||
:class="{
|
:class="{
|
||||||
btn: true,
|
btn: true,
|
||||||
'btn-send': true,
|
'btn-send': true,
|
||||||
disabled: !question
|
disabled: !questionValue
|
||||||
}"
|
}"
|
||||||
@click="onSubmit"
|
@click="onSubmit"
|
||||||
>
|
>
|
||||||
<font-awesome-icon icon="fa-solid fa-location-arrow" class="icon icon-send" />
|
<font-awesome-icon icon="fa-solid fa-location-arrow" class="icon icon-send" />
|
||||||
</span>
|
</span>
|
||||||
<el-input
|
<!-- add this textarea -->
|
||||||
|
<textarea
|
||||||
|
ref="textarea"
|
||||||
v-model="questionValue"
|
v-model="questionValue"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
class="input"
|
class="input"
|
||||||
type="textarea"
|
|
||||||
:placeholder="$t('chat.message.newMessagePlaceholder')"
|
:placeholder="$t('chat.message.newMessagePlaceholder')"
|
||||||
|
:style="{ height: inputHeight }"
|
||||||
@keydown.enter.exact.prevent="onSubmit"
|
@keydown.enter.exact.prevent="onSubmit"
|
||||||
>
|
@input="adjustTextareaHeight"
|
||||||
</el-input>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
<p class="info">{{ $t('chat.message.howToUse') }}</p>
|
<p class="info">{{ $t('chat.message.howToUse') }}</p>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElInput, ElMessage, ElTooltip, ElUpload } from 'element-plus';
|
// import { ElInput, ElMessage, ElTooltip, ElUpload } from 'element-plus';
|
||||||
|
import { ElMessage, ElTooltip, ElUpload } from 'element-plus';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||||
import { IChatModel } from '@/models';
|
import { IChatModel } from '@/models';
|
||||||
import { getBaseUrlData } from '@/utils';
|
import { getBaseUrlData } from '@/utils';
|
||||||
@@ -56,7 +59,7 @@ import { CHAT_MODEL_GPT_4_VISION } from '@/constants';
|
|||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'InputBox',
|
name: 'InputBox',
|
||||||
components: {
|
components: {
|
||||||
ElInput,
|
// ElInput,
|
||||||
ElTooltip,
|
ElTooltip,
|
||||||
FontAwesomeIcon,
|
FontAwesomeIcon,
|
||||||
ElUpload
|
ElUpload
|
||||||
@@ -80,6 +83,7 @@ export default defineComponent({
|
|||||||
emits: ['update:question', 'update:references', 'submit'],
|
emits: ['update:question', 'update:references', 'submit'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
inputHeight: '35px', //add inputHeight
|
||||||
questionValue: this.question,
|
questionValue: this.question,
|
||||||
fileList: [],
|
fileList: [],
|
||||||
uploadUrl: getBaseUrlData() + '/api/v1/files/'
|
uploadUrl: getBaseUrlData() + '/api/v1/files/'
|
||||||
@@ -121,6 +125,16 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// add textarea method
|
||||||
|
adjustTextareaHeight() {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
const textarea = this.$refs.textarea;
|
||||||
|
if (textarea) {
|
||||||
|
textarea.style.height = '35px'; // 先重置高度
|
||||||
|
textarea.style.height = textarea.scrollHeight + 'px'; // 设置高度为内容的实际高度
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
if (!this.question) {
|
if (!this.question) {
|
||||||
return;
|
return;
|
||||||
@@ -138,19 +152,25 @@ export default defineComponent({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.upload {
|
textarea.input {
|
||||||
display: flex;
|
min-height: 35px;
|
||||||
height: 40px;
|
max-height: 350px;
|
||||||
.el-upload-list {
|
border: none;
|
||||||
flex: 1;
|
background: none;
|
||||||
|
box-shadow: none;
|
||||||
|
resize: none;
|
||||||
|
line-height: 30px;
|
||||||
|
width: calc(100% - 80px);
|
||||||
|
margin-left: 30px;
|
||||||
}
|
}
|
||||||
|
textarea.input:focus {
|
||||||
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-box {
|
.input-box {
|
||||||
|
// height: auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
.input {
|
.input {
|
||||||
textarea {
|
textarea {
|
||||||
height: auto;
|
|
||||||
max-height: 100px;
|
max-height: 100px;
|
||||||
border: none;
|
border: none;
|
||||||
background: none;
|
background: none;
|
||||||
@@ -159,6 +179,11 @@ export default defineComponent({
|
|||||||
line-height: 30px;
|
line-height: 30px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.el-upload-list {
|
||||||
|
position: absolute;
|
||||||
|
width: 400px;
|
||||||
|
bottom: 45px;
|
||||||
|
}
|
||||||
|
|
||||||
.el-textarea.is-disabled .el-textarea__inner {
|
.el-textarea.is-disabled .el-textarea__inner {
|
||||||
background-color: initial;
|
background-color: initial;
|
||||||
@@ -174,7 +199,7 @@ export default defineComponent({
|
|||||||
background: none;
|
background: none;
|
||||||
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
|
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
|
||||||
.upload {
|
.upload {
|
||||||
display: block;
|
display: inline-block;
|
||||||
&.disabled {
|
&.disabled {
|
||||||
.btn-upload {
|
.btn-upload {
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
@@ -187,6 +212,7 @@ export default defineComponent({
|
|||||||
.input {
|
.input {
|
||||||
border: none;
|
border: none;
|
||||||
width: calc(100% - 80px);
|
width: calc(100% - 80px);
|
||||||
|
margin-left: 30px;
|
||||||
}
|
}
|
||||||
.btn {
|
.btn {
|
||||||
display: block;
|
display: block;
|
||||||
|
|||||||
Reference in new issue
Block a user