| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <template>
- <div class="write-new-comment">
- <label>
- <input ref="title" @keydown="handleTitleKey" type="text" v-model="title" :placeholder="placeholder || '讨论主题'" maxlength="100">
- </label>
- <label>
- <textarea @keyup="handleContentKey" ref="content" v-model="content" placeholder="详细内容"></textarea>
- </label>
- <icon-button class="send-button" theme="green" @click="handleSubmitComment" :size="32">send</icon-button>
- </div>
- </template>
- <script>
- import IconButton from '@/components/Basic/IconButton'
- import { mapState } from 'vuex'
- export default {
- props: ['placeholder'],
- components: { IconButton },
- computed: {
- ...mapState({
- focus: state => state.pdf.focus
- })
- },
- watch: {
- focus: {
- handler () {
- this.focus && this.$refs.title.focus()
- }
- }
- },
- data () {
- return {
- title: '',
- content: ''
- }
- },
- methods: {
- handleSubmitComment () {
- if (!(this.title && this.content)) {
- this.$setInfoMessage('主题和内容均需要填写')
- return
- }
- this.$emit('comment-submit', { title: this.title, content: this.content })
- },
- resetContent () {
- this.title = ''
- this.content = ''
- },
- handleTitleKey (e) {
- if (this.title && !e.isComposing && e.key === 'Enter') {
- this.$refs.content.focus()
- e.preventDefault()
- }
- if (e.shiftKey && !e.isComposing && e.key === 'Enter') {
- e.preventDefault()
- this.handleSubmitComment()
- }
- },
- handleContentKey (e) {
- if (e.shiftKey && !e.isComposing && e.key === 'Enter') {
- e.preventDefault()
- this.handleSubmitComment()
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import '~@/style/theme.scss';
- .write-new-comment {
- position: relative;
- }
- input, textarea {
- box-sizing: border-box;
- font-size: 14px;
- color: #3a4a5a;
- border-radius: 4px;
- border: none;
- outline: none;
- width: 100%;
- height: 36px;
- line-height: 1.6;
- padding: 8px;
- transition: .2s;
- background-color: transparent;
- &:hover {
- border-color: #6a7a8a;
- transform: translateY(-1px);
- }
- &::placeholder {
- color: #9aaaba;
- }
- }
- input {
- border-radius: 4px 4px 0 0;
- border: 1px solid #bacada;
- }
- textarea {
- transform: translateY(-1px);
- border-radius: 0 0 4px 4px;
- border: 1px solid #bacada;
- min-height: 96px;
- padding-bottom: 32px;
- height: 100%;
- resize: vertical;
- }
- .send-button {
- position: absolute;
- bottom: 12px;
- right: 12px;
- background: white;
- &:hover {
- background: lighten($theme-green-light, 2);
- }
- }
- </style>
|