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
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 {
@@ -42,13 +84,28 @@ export default class EditLessonScreenInner3 extends Vue {
42
84
type: Object as () => formData ,
43
85
required: true ,
44
86
default : () => ({
45
- videoUrl: ' ' ,
87
+ videoUrl: null ,
46
88
videoTitle: ' ' ,
47
89
videoThumbnailUrl: ' ' ,
48
90
}),
49
91
})
50
92
public value! : formData
51
93
94
+ videoSearchWord: string = ' '
95
+ videoSearchResult: formData [] = []
96
+ page: number = 1
97
+ pageSize: number = 5
98
+ length: number = 0
99
+ displayLists: formData [] = []
100
+
101
+ mounted() {
102
+ fetch (' /data/movies.json' )
103
+ .then ((res ) => res .json ())
104
+ .then ((data ) => {
105
+ movies = data
106
+ })
107
+ }
108
+
52
109
private get form(): formData {
53
110
return this .value
54
111
}
@@ -58,9 +115,61 @@ export default class EditLessonScreenInner3 extends Vue {
58
115
this .input (this .tempFormData )
59
116
}
60
117
61
- @Watch (' value' , { deep: true })
62
- onChangeValueFormData() {
63
- this .tempFormData = this .value
118
+ private handleVideoSearchWord() {
119
+ if (this .videoSearchWord ) {
120
+ this .page = 1
121
+ this .videoSearchResult = movies
122
+ .filter ((v ) => {
123
+ const fullText = Object .keys (v )
124
+ .map ((k ) => v [k ])
125
+ .join ()
126
+ return fullText .includes (this .videoSearchWord )
127
+ })
128
+ .map ((v ) => {
129
+ const videoId = v [' 教材_ID' ]
130
+ const videoType = parseInt (videoId .slice (5 , 6 ))
131
+ const nfsMovieUrl = ' https://www2.nhk.or.jp/school/movie/'
132
+ const videoDirectory = videoId .slice (0 , 8 )
133
+ let videoThumbnailUrl = ` https://www.nhk.or.jp/das/image/${videoDirectory }/${videoId }_S_005.jpg `
134
+ let videoUrl
135
+ switch (videoType ) {
136
+ case 1 :
137
+ case 2 :
138
+ videoUrl = ` ${nfsMovieUrl }bangumi.cgi?das_id=${videoId }&p=box `
139
+ break
140
+ case 3 :
141
+ case 4 :
142
+ videoUrl = ` ${nfsMovieUrl }clip.cgi?das_id=${videoId }&p=box `
143
+ break
144
+ default :
145
+ videoUrl = null
146
+ videoThumbnailUrl = ' '
147
+ }
148
+ return {
149
+ videoUrl ,
150
+ videoTitle: v [' 教材_タイトル' ],
151
+ videoSubTitle: v [' 教材_サブタイトル' ],
152
+ videoDescription: v [' 教材_説明' ],
153
+ videoPlayTime: v [' 教材_再生時間' ],
154
+ videoThumbnailUrl ,
155
+ }
156
+ })
157
+
158
+ this .length = Math .ceil (this .videoSearchResult .length / this .pageSize )
159
+
160
+ this .displayLists = this .videoSearchResult .slice (0 , this .pageSize )
161
+ }
162
+ }
163
+
164
+ private registerVideoUrl(url : string ) {
165
+ this .tempFormData .videoUrl = url
166
+ }
167
+
168
+ private pageChange(pageNumber : number ) {
169
+ this .displayLists = this .videoSearchResult .slice (
170
+ this .pageSize * (pageNumber - 1 ),
171
+ this .pageSize * pageNumber
172
+ )
64
173
}
65
174
66
175
/* CORS 回避必須
@@ -91,3 +200,23 @@ export default class EditLessonScreenInner3 extends Vue {
91
200
}
92
201
}
93
202
</script >
203
+
204
+ <style lang="scss" scoped>
205
+ .Button {
206
+ color : $color-white ;
207
+ margin-bottom : 20px ;
208
+ }
209
+ .SearchResult {
210
+ color : $color-white ;
211
+ margin-bottom : 20px ;
212
+ }
213
+ .SearchResultItem {
214
+ margin-bottom : 12px ;
215
+ }
216
+ .SearchResultLink {
217
+ color : $color-white ;
218
+ }
219
+ .SearchResultDescription {
220
+ margin : 0 ;
221
+ }
222
+ </style >
0 commit comments