6
6
label =" video"
7
7
placeholder =" https://"
8
8
/>
9
- < video-thumbnail
10
- v-if = " tempFormData.videoTitle && tempFormData.videoThumbnailUrl "
11
- :caption = " tempFormData.videoTitle "
12
- :title =" $t('components.editing_screen.labels.video_thumbnail ')"
13
- :thumbnail-url = " tempFormData.videoThumbnailUrl "
9
+
10
+ < editor-input-field-pickable
11
+ v-model = " videoSearchWord "
12
+ :title =" $t('components.editing_screen.labels.video_keyword ')"
13
+ :placeholders = " $t('components.editing_screen.placeholder.video_keyword') "
14
14
/>
15
+
16
+ <button class =" Button" @click =" handleVideoSearchWord" >検索する</button >
17
+
18
+ <div v-if =" videoSearchResult.length > 0" class =" SearchResult" >
19
+ <h3 >NHK For Schoolの動画検索結果</h3 >
20
+ <ul >
21
+ <li v-for =" (v, i) in displayLists" :key =" i" class =" SearchResultItem" >
22
+ <component
23
+ :is =" v.videoUrl ? 'a' : 'span'"
24
+ :href =" v.videoUrl"
25
+ :target =" v.videoUrl ? '_blank' : null"
26
+ class =" SearchResultLink"
27
+ >
28
+ {{ v.videoTitle }}&emsp ; {{ v.videoSubTitle }}
29
+ </component >
30
+ <p class =" SearchResultDescription" >{{ v.videoDescription }}</p >
31
+ <span >{{ v.videoPlayTime }}</span >
32
+ <br v-if =" v.videoThumbnailUrl" />
33
+ <img
34
+ v-if =" v.videoThumbnailUrl"
35
+ :src =" v.videoThumbnailUrl"
36
+ :alt =" v.videoTitle"
37
+ width =" 240"
38
+ />
39
+ <br v-if =" v.videoUrl" />
40
+ <button
41
+ v-if =" v.videoUrl"
42
+ class =" Button"
43
+ @click =" registerVideoUrl(v.videoUrl)"
44
+ >
45
+ 参考動画URLに登録する
46
+ </button >
47
+ </li >
48
+ </ul >
49
+ <v-pagination
50
+ v-model =" page"
51
+ :length =" length"
52
+ :total-visible =" 5"
53
+ @input =" pageChange"
54
+ />
55
+ </div >
15
56
</div >
16
57
</template >
17
58
18
59
<script lang="ts">
19
60
import { Vue , Component , Prop , Emit , Watch } from ' vue-property-decorator'
20
- import VideoThumbnail from ' @/components/VideoThumbnail.vue'
21
61
import EditorInputFieldPickable from ' ~/components/EditorInputFieldPickable.vue'
22
62
63
+ let movies: any [] = []
64
+
23
65
export type formData = {
24
- videoUrl: string
66
+ videoUrl: string | null
25
67
videoTitle: string
26
68
videoThumbnailUrl: string | null
27
69
}
70
+
28
71
@Component ({
29
72
components: {
30
73
EditorInputFieldPickable ,
31
- VideoThumbnail,
32
74
},
33
75
})
34
76
export default class EditLessonScreenInner3 extends Vue {
@@ -43,13 +85,28 @@ export default class EditLessonScreenInner3 extends Vue {
43
85
type: Object as () => formData ,
44
86
required: true ,
45
87
default : () => ({
46
- videoUrl: ' ' ,
88
+ videoUrl: null ,
47
89
videoTitle: ' ' ,
48
90
videoThumbnailUrl: ' ' ,
49
91
}),
50
92
})
51
93
public value! : formData
52
94
95
+ videoSearchWord: string = ' '
96
+ videoSearchResult: formData [] = []
97
+ page: number = 1
98
+ pageSize: number = 5
99
+ length: number = 0
100
+ displayLists: formData [] = []
101
+
102
+ mounted() {
103
+ fetch (' /data/movies.json' )
104
+ .then ((res ) => res .json ())
105
+ .then ((data ) => {
106
+ movies = data
107
+ })
108
+ }
109
+
53
110
private get form(): formData {
54
111
return this .value
55
112
}
@@ -59,9 +116,61 @@ export default class EditLessonScreenInner3 extends Vue {
59
116
this .input (this .tempFormData )
60
117
}
61
118
62
- @Watch (' value' , { deep: true })
63
- onChangeValueFormData() {
64
- this .tempFormData = this .value
119
+ private handleVideoSearchWord() {
120
+ if (this .videoSearchWord ) {
121
+ this .page = 1
122
+ this .videoSearchResult = movies
123
+ .filter ((v ) => {
124
+ const fullText = Object .keys (v )
125
+ .map ((k ) => v [k ])
126
+ .join ()
127
+ return fullText .includes (this .videoSearchWord )
128
+ })
129
+ .map ((v ) => {
130
+ const videoId = v [' 教材_ID' ]
131
+ const videoType = parseInt (videoId .slice (5 , 6 ))
132
+ const nfsMovieUrl = ' https://www2.nhk.or.jp/school/movie/'
133
+ const videoDirectory = videoId .slice (0 , 8 )
134
+ let videoThumbnailUrl = ` https://www.nhk.or.jp/das/image/${videoDirectory }/${videoId }_S_005.jpg `
135
+ let videoUrl
136
+ switch (videoType ) {
137
+ case 1 :
138
+ case 2 :
139
+ videoUrl = ` ${nfsMovieUrl }bangumi.cgi?das_id=${videoId }&p=box `
140
+ break
141
+ case 3 :
142
+ case 4 :
143
+ videoUrl = ` ${nfsMovieUrl }clip.cgi?das_id=${videoId }&p=box `
144
+ break
145
+ default :
146
+ videoUrl = null
147
+ videoThumbnailUrl = ' '
148
+ }
149
+ return {
150
+ videoUrl ,
151
+ videoTitle: v [' 教材_タイトル' ],
152
+ videoSubTitle: v [' 教材_サブタイトル' ],
153
+ videoDescription: v [' 教材_説明' ],
154
+ videoPlayTime: v [' 教材_再生時間' ],
155
+ videoThumbnailUrl ,
156
+ }
157
+ })
158
+
159
+ this .length = Math .ceil (this .videoSearchResult .length / this .pageSize )
160
+
161
+ this .displayLists = this .videoSearchResult .slice (0 , this .pageSize )
162
+ }
163
+ }
164
+
165
+ private registerVideoUrl(url : string ) {
166
+ this .tempFormData .videoUrl = url
167
+ }
168
+
169
+ private pageChange(pageNumber : number ) {
170
+ this .displayLists = this .videoSearchResult .slice (
171
+ this .pageSize * (pageNumber - 1 ),
172
+ this .pageSize * pageNumber
173
+ )
65
174
}
66
175
67
176
/* CORS 回避必須
@@ -92,3 +201,23 @@ export default class EditLessonScreenInner3 extends Vue {
92
201
}
93
202
}
94
203
</script >
204
+
205
+ <style lang="scss" scoped>
206
+ .Button {
207
+ color : $color-white ;
208
+ margin-bottom : 20px ;
209
+ }
210
+ .SearchResult {
211
+ color : $color-white ;
212
+ margin-bottom : 20px ;
213
+ }
214
+ .SearchResultItem {
215
+ margin-bottom : 12px ;
216
+ }
217
+ .SearchResultLink {
218
+ color : $color-white ;
219
+ }
220
+ .SearchResultDescription {
221
+ margin : 0 ;
222
+ }
223
+ </style >
0 commit comments