|
1 | 1 | <template lang="html">
|
2 | 2 | <div class="list">
|
| 3 | + <!-- 电影列表 --> |
3 | 4 | <mu-table :fixedHeader="true" :showCheckbox="false" >
|
4 | 5 | <mu-thead>
|
5 | 6 | <mu-tr>
|
6 |
| - <mu-th>ID</mu-th> |
7 | 7 | <mu-th>电影海报</mu-th>
|
8 | 8 | <mu-th>电影名称</mu-th>
|
9 |
| - <mu-th>上映年份</mu-th> |
10 |
| - <mu-th>主要演员</mu-th> |
| 9 | + <mu-th>简介</mu-th> |
11 | 10 | <mu-th>评分</mu-th>
|
12 | 11 | <mu-th>操作</mu-th>
|
13 | 12 | </mu-tr>
|
14 | 13 | </mu-thead>
|
15 | 14 | <mu-tbody>
|
16 | 15 | <mu-tr v-for="movie of movies">
|
17 |
| - <mu-td>{{ movie.id }}</mu-td> |
18 |
| - <mu-td><img :src="movie.image" :title="movie.original_title"></mu-td> |
19 |
| - <mu-td>{{ movie.title }}</mu-td> |
20 |
| - <mu-td>{{ movie.year }}</mu-td> |
| 16 | + <mu-td><img class="movie-poster" :src="movie.poster"></mu-td> |
| 17 | + <mu-td><h3>{{ movie.title }}</h3></mu-td> |
| 18 | + <mu-td style="white-space: normal;padding:12px;">{{ movie.introduction }}</mu-td> |
| 19 | + <mu-td class="movie-rating">{{ movie.rating }}</mu-td> |
21 | 20 | <mu-td>
|
22 |
| - <p v-for="cast of movie.casts">{{ cast.name }}</p> |
23 |
| - </mu-td> |
24 |
| - <mu-td>{{ movie.rating }}</mu-td> |
25 |
| - <mu-td> |
26 |
| - <mu-raised-button label="修改" primary/> |
27 |
| - <mu-raised-button label="删除" secondary/> |
| 21 | + <mu-raised-button @click="openEditMovieModal(movie)" label="修改" primary/> |
| 22 | + <mu-raised-button @click="removeMovie(movie)" label="删除" secondary/> |
28 | 23 | </mu-td>
|
29 | 24 | </mu-tr>
|
30 | 25 | </mu-tbody>
|
31 | 26 | </mu-table>
|
32 |
| - <mu-float-button icon="add" class="add-movie-btn" @click="addMovie"/> |
33 |
| - <vodal :show="showModal" animation="slideDown" @hide="show = false" :closeButton="false"> |
34 |
| - |
| 27 | + <!-- 添加电影按钮 --> |
| 28 | + <mu-float-button icon="add" class="add-movie-button" backgroundColor @click="openAddMovieModal"/> |
| 29 | + <!-- 添加电影表单 --> |
| 30 | + <vodal :show="addMovieModal" animation="slideDown" :width="500" :height="400" :closeButton="false"> |
| 31 | + <mu-text-field v-model="title" fullWidth icon="movie" label="电影名称" labelFloat/><br/> |
| 32 | + <mu-text-field v-model="poster" fullWidth icon="picture_in_picture" label="海报地址" labelFloat/><br/> |
| 33 | + <mu-text-field v-model="introduction" fullWidth icon="description" label="简介" labelFloat/><br/> |
| 34 | + <mu-text-field v-model="rating" fullWidth icon="star" label="评分" labelFloat/><br/> |
| 35 | + <mu-raised-button @click="closeModal" label="取消" icon="undo" /> |
| 36 | + <mu-raised-button @click="addMovie" label="确定" icon="check" primary/> |
| 37 | + </vodal> |
| 38 | + <!-- 编辑电影表单 --> |
| 39 | + <vodal :show="editMovieModal" animation="slideDown" :width="500" :height="400" :closeButton="false"> |
| 40 | + <mu-text-field v-model="title" fullWidth icon="movie" label="电影名称" labelFloat/><br/> |
| 41 | + <mu-text-field v-model="poster" fullWidth icon="picture_in_picture" label="海报地址" labelFloat/><br/> |
| 42 | + <mu-text-field v-model="introduction" fullWidth icon="description" label="简介" labelFloat/><br/> |
| 43 | + <mu-text-field type="number" v-model="rating" fullWidth icon="star" label="评分" labelFloat/><br/> |
| 44 | + <mu-raised-button @click="closeModal" label="取消" icon="undo" /> |
| 45 | + <mu-raised-button @click="editMovie" label="确定" icon="check" primary/> |
35 | 46 | </vodal>
|
| 47 | + <!-- 删除电影对话框 --> |
| 48 | + <mu-dialog :open="showDialog" title="确定删除电影?" @close="closeDialog"> |
| 49 | + <mu-raised-button slot="actions" @click="closeDialog" label="取消"/> |
| 50 | + <mu-raised-button slot="actions" primary @click="closeDialog" label="确定"/> |
| 51 | + </mu-dialog> |
36 | 52 | </div>
|
37 | 53 | </template>
|
38 | 54 |
|
39 | 55 | <script>
|
40 | 56 | export default {
|
41 | 57 | created() {
|
42 | 58 | this.getMovies()
|
| 59 | + document.title = this.$route.name |
43 | 60 | },
|
44 | 61 | components:{},
|
45 | 62 | data() {
|
46 | 63 | return {
|
| 64 | + title : '', |
| 65 | + poster : '', |
| 66 | + rating : null, |
| 67 | + introduction : '', |
| 68 | + movie_id : '', |
47 | 69 | movies: [],
|
48 |
| - showModal : false |
| 70 | + addMovieModal : false, |
| 71 | + editMovieModal : false, |
| 72 | + showDialog : false |
49 | 73 | }
|
50 | 74 | },
|
51 | 75 | methods: {
|
52 | 76 | getMovies() {
|
53 | 77 | this.$http.get('/api/movie')
|
54 | 78 | .then(res => {
|
| 79 | + console.dir(res.data) |
55 | 80 | this.movies = res.data
|
56 | 81 | })
|
57 | 82 | .catch(err => {
|
58 | 83 | this.toastr.error(`${err.message}`, 'ERROR!')
|
59 | 84 | console.log(err)
|
60 | 85 | })
|
61 | 86 | },
|
| 87 | + closeDialog(){ |
| 88 | + this.showDialog = false |
| 89 | + }, |
| 90 | + openAddMovieModal(){ |
| 91 | + this.addMovieModal = true |
| 92 | + }, |
| 93 | + openEditMovieModal(movie){ |
| 94 | + this.editMovieModal = true |
| 95 | + this.title = movie.title |
| 96 | + this.rating = movie.rating |
| 97 | + this.introduction = movie.introduction |
| 98 | + this.poster = movie.poster |
| 99 | + this.movie_id = movie._id |
| 100 | + }, |
| 101 | + closeModal(){ |
| 102 | + this.addMovieModal = false |
| 103 | + this.editMovieModal = false |
| 104 | + }, |
62 | 105 | addMovie(){
|
63 |
| - this.showModal = true |
64 |
| - } |
| 106 | + this.$http.post('/api/movie',{ |
| 107 | + title : this.title, |
| 108 | + poster : this.poster, |
| 109 | + introduction : this.introduction, |
| 110 | + rating : this.rating |
| 111 | + }) |
| 112 | + .then(res => { |
| 113 | + this.toastr.success('保存成功.') |
| 114 | + console.log(res.data) |
| 115 | + this.addMovieModal = false |
| 116 | + this.title = '' |
| 117 | + this.rating = 0 |
| 118 | + this.poster = '' |
| 119 | + this.introduction = '' |
| 120 | + this.getMovies() |
| 121 | + }) |
| 122 | + .catch(e => { |
| 123 | + this.toastr.warn('保存失败!') |
| 124 | + console.log(e) |
| 125 | + }) |
| 126 | + }, |
| 127 | + cancelAddMovie(){ |
| 128 | + this.addMovieModal = false |
| 129 | + this.title = '' |
| 130 | + this.rating = 0 |
| 131 | + this.poster = '' |
| 132 | + this.introduction = '' |
| 133 | + }, |
| 134 | + editMovie(){ |
| 135 | + let id = this.movie_id |
| 136 | + this.$http.put(`/api/movie/${id}`,{ |
| 137 | + title : this.title, |
| 138 | + poster : this.poster, |
| 139 | + introduction : this.introduction, |
| 140 | + rating : this.rating, |
| 141 | + }) |
| 142 | + .then(res => { |
| 143 | + this.toastr.success("更新电影成功!") |
| 144 | + console.log(res.data) |
| 145 | + this.closeModal() |
| 146 | + this.getMovies() |
| 147 | + }) |
| 148 | + .catch(err => console.log(err)) |
| 149 | + }, |
| 150 | + removeMovie(movie){ |
| 151 | + let id = movie._id |
| 152 | + this.showDialog = true |
| 153 | + this.$http.delete(`/api/movie/${id}`) |
| 154 | + .then(res => { |
| 155 | + this.toastr.success("删除成功.") |
| 156 | + console.log(res.data) |
| 157 | + this.closeDialog() |
| 158 | + this.getMovies() |
| 159 | + }) |
| 160 | + .catch(e => console.log(e)) |
| 161 | + }, |
| 162 | + searchMovie(){} |
65 | 163 | }
|
66 | 164 | }
|
67 | 165 | </script>
|
68 | 166 |
|
69 | 167 | <style lang="css">
|
70 |
| - .list{ |
71 |
| - } |
72 |
| - .add-movie-btn{ |
73 |
| - position: fixed; |
74 |
| - bottom: 50px; |
| 168 | + .movie-poster{ |
| 169 | + width: 100px; |
75 | 170 | }
|
76 | 171 | </style>
|
0 commit comments