ReleaseStory.vue
4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<template>
  <div class="releaseStory">
    <div class="btns">
      <span @click="AddStory(2)">存草稿</span>
      <span @click="AddStory(3)">发布</span>
    </div>
    <div class="cont">
      <div class="item">
        <input v-model="title" type="text" placeholder="点击输入文章标题" />
      </div>
      <div class="item">
        <textarea v-model="content" name="" id="" cols="30" rows="10" placeholder="记录下你的研学故事,越详实越容易被推荐~"></textarea>
        <p>写120字有机会被评为<span>优质故事</span></p>
      </div>
    </div>
    <div class="imgs">
      <img :src="n.imgUrl" alt="" v-for="(n, i) in imgsrc" :key="i" />
      <div class="selectImg">
        <imgCut @callback="callback" :width="200" :height="200">
          <van-icon name="plus" />
        </imgCut>
      </div>
    </div>
    <div class="base">
      <van-icon name="send-gift" />
      <span>{{ courseInfo.course_name }}</span>
      <van-icon class="arrow" name="arrow" />
    </div>
  </div>
</template>
<script>
import { imgCut } from 'vue-imgcut'
export default {
  data() {
    return {
      userInfo: '',
      courseInfo: '',
      title: '',
      content: '',
      imgsrc: [],
    }
  },
  components: {
    imgCut,
  },
  created() {
    var that = this
    var userInfo = localStorage.getItem('userInfo')
    if (userInfo) {
      this.userInfo = JSON.parse(userInfo)
    }
    var courseInfo = localStorage.getItem('YXNowCourse')
    if (courseInfo) {
      this.courseInfo = JSON.parse(courseInfo)
    }
    if (this.courseInfo.storyId > 0) {
      this.$dialog
        .confirm({
          title: '提示',
          message: '当前存在一条草稿记录,是否使用?',
        })
        .then(() => {
          that.http
            .GetStory({
              id: this.courseInfo.storyId,
            })
            .then(function(res) {
              that.title = res.data.title
              that.content = res.data.content
              if (res.data.imgList.length > 0) {
                res.data.imgList.forEach(function(n, i) {
                  that.imgsrc.push({
                    imgUrl: n.imgUrl,
                  })
                })
              }
            })
        })
        .catch(() => {
          // on cancel
        })
    }
  },
  methods: {
    AddStory(type) {
      var that = this
      if (this.imgsrc.length == 0) {
        this.$toast.fail('请上传图片')
        return false
      }
      this.$toast.loading({
        message: '请求中...',
      })
      this.http
        .AddStory({
          title: this.title,
          content: this.content,
          courseId: this.courseInfo.id,
          userId: this.userInfo.centerNo,
          imgList: this.imgsrc,
          state: type,
        })
        .then(function(res) {
          that.$toast.clear()
          if (res.status == 1) {
            if (type == 3) {
              that.$toast.success('发送成功')
              setTimeout(function() {
                that.$router.push({ path: '/MyStory' })
              }, 1000)
            } else {
              that.$toast.success('保存成功')
            }
          }
        })
    },
    callback(img) {
      this.imgsrc.push({
        imgUrl: img,
      })
    },
  },
}
</script>
<style lang="stylus" scoped>
.releaseStory{
	padding 40px
	box-sizing border-box
	.btns{
		text-align right
		span{
			display inline-block
			padding 6px 10px
			width 100px
			text-align center
			margin-left 10px
			border-radius 100px
			border 2px solid #ccc
			font-size 1.4rem
		}
		span:last-child{
			background-color #19D075
			color white
			border none
		}
	}
	.cont{
		input{
			border none
			width 100%
			height 76px
			font-size 1.4rem
			line-height 76px
		}
		textarea{
			width 100%
			font-size 1.2rem
			border none
		}
		p{
			text-align right
			font-size 1.2rem
			color #909090
			span{
				color #09CE6C
			}
		}
	}
	.imgs{
		padding 40px 0
		img:first-child::after{
			content '封面图片'
			position absolute
			bottom 0
			left 0
			right 0
			background-color rgba(0,0,0,.5)
			color white
			font-size 1.2rem
			padding 6px
			z-index 1000
		}
		img{
			position relative
			display inline-block
			vertical-align top
			width 100px
			height 100px
			border-radius 10px
			margin-right 20px
		}
		.selectImg{
			display inline-block
			vertical-align top
			width 100px
			height 100px
			text-align center
			line-height 100px
			border-radius 10px
			border 2px solid #eee
			font-size 2rem
			color #eee
		}
	}
	.base{
		padding 40px 40px 0
		box-sizing border-box
		position relative
		color #09CE6D
		word-break: break-all;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
		font-size 1.2rem
		i{
			position absolute
			left 0
			top 40px
			font-size 1.6rem
		}
		.arrow{
			left initial
			right 0
			top 40px
		}
	}
}
</style>