App.vue 1.9 KB
Newer Older
6
UPDATE  
64104061f23fda247c679fa8 已提交
1
<template>
6
update  
64104061f23fda247c679fa8 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  <div class="container ivu-p">
    <div class="dialog">
      <template v-for="(item, index) in dialogs" :key="index">
        <div class="dialog-item" :class="{ 'dialog-item-me': item.role === 'me', 'dialog-item-ai': item.role === 'ai' }">
          <div class="dialog-item-main">{{ item.text }}</div>
        </div>
      </template>
    </div>
    <div class="prompt ivu-mt">
      <Input
       v-model="prompt" 
       type="textarea" 
       :autosize="{ minRows: 4, maxRows: 6 }" 
       placeholder="输入你的问题" 
      />
6
update  
64104061f23fda247c679fa8 已提交
17 18 19 20 21 22 23 24
      <Row class="ivu-mt">
        <Col>
          <Button type="primary" size="large" icon="md-send" :loading="loading" @click="handleSend">发送</Button>
        </Col>
        <Col>
          <Button size="large" class="ivu-ml" icon="md-add" :disabled="loading" @click="handleNewChat">新对话</Button>
        </Col>
      </Row>
6
update  
64104061f23fda247c679fa8 已提交
25
    </div>
6
622eda98dfef6c4fdb84ccca 已提交
26
  </div>
6
UPDATE  
64104061f23fda247c679fa8 已提交
27
</template>
6
update  
64104061f23fda247c679fa8 已提交
28 29 30 31 32 33 34 35 36
<script>
  export default {
    data () {
      return {
        prompt: '',
        loading: false,
        dialogs: [
          {
            role: 'me',
6
update  
64104061f23fda247c679fa8 已提交
37
            text: '你好'
6
update  
64104061f23fda247c679fa8 已提交
38 39 40
          },
          {
            role: 'ai',
6
update  
64104061f23fda247c679fa8 已提交
41
            text: '你也好'
6
update  
64104061f23fda247c679fa8 已提交
42 43 44 45 46 47 48 49
          }
        ]
      }
    },
    methods: {
      handleSend () {
        if (this.loading) return;
        this.loading = true;
6
update  
64104061f23fda247c679fa8 已提交
50 51 52 53
        // todo
      },
      handleNewChat () {
        this.dialogs = [];
6
update  
64104061f23fda247c679fa8 已提交
54 55 56
      }
    }
  }
6
622eda98dfef6c4fdb84ccca 已提交
57
</script>
6
update  
64104061f23fda247c679fa8 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
<style>
  .container{
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .dialog{
    flex: 1;
    overflow: auto;
  }
  .dialog-item{
    display: flex;
  }
  .dialog-item-main{
    max-width: 80%;
    padding: 8px;
    word-wrap: break-word;
    margin-top: 16px;
    border-radius: 4px;
  }
  .dialog-item-me{
    justify-content: flex-end;
  }
  .dialog-item-me .dialog-item-main{
    background-color: antiquewhite;
  }
  .dialog-item-ai .dialog-item-main{
    background-color: #eee;
  }
</style>