index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="home">
  3. <div class="home-title">
  4. <span>教材列表</span>
  5. <el-button type="primary" @click="createBook">创建教材</el-button>
  6. </div>
  7. <div class="home-tabs">
  8. <span
  9. v-for="{ label, value } in publishStatusList"
  10. :key="value"
  11. :class="['tab-item', value === publish_status ? 'active' : '']"
  12. @click="publish_status = value"
  13. >
  14. {{ label }}
  15. </span>
  16. </div>
  17. <div class="search">
  18. <span class="search-name">搜索</span>
  19. <el-input
  20. v-model="name"
  21. placeholder="全部"
  22. suffix-icon="el-icon-search"
  23. @keyup.enter.native="pageQueryBookList"
  24. />
  25. <span class="search-name">创建者</span>
  26. <el-select v-model="creator_id" placeholder="全部" @change="pageQueryBookList">
  27. <el-option label="-全部- " value="" />
  28. <el-option
  29. v-for="{ user_id, user_real_name } in user_list"
  30. :key="user_id"
  31. :label="user_real_name"
  32. :value="user_id"
  33. />
  34. </el-select>
  35. </div>
  36. <el-table :data="data" height="100%">
  37. <el-table-column label="序号" width="64">
  38. <template slot-scope="{ $index }">
  39. <span>{{ $index + 1 }}</span>
  40. </template>
  41. </el-table-column>
  42. <el-table-column prop="name" label="教材名称" width="248" />
  43. <el-table-column prop="label_name_list_desc" label="标签" width="124" />
  44. <el-table-column prop="creator_name" label="创建者" width="160" />
  45. <el-table-column prop="create_time" label="创建时间" width="180" />
  46. <el-table-column prop="last_modifier_name" label="最近编辑" width="180" />
  47. <el-table-column prop="last_modify_time" label="最近编辑时间" width="180" />
  48. <el-table-column prop="description" label="简介" />
  49. <el-table-column prop="operation" label="操作" width="245" fixed="right">
  50. <template slot-scope="{ row }">
  51. <span class="link" @click="editBook(row.id)">编辑</span>
  52. <span
  53. :class="['link', { danger: row.publish_status === publishStatusList[0].value }]"
  54. @click="
  55. row.publish_status === publishStatusList[0].value ? setUnpublishForBook(row.id) : listingBook(row.id)
  56. "
  57. >
  58. {{ row.publish_status === publishStatusList[0].value ? '下架' : '上架' }}
  59. </span>
  60. <span class="link danger" @click="deleteBook(row.id)">删除</span>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. <el-pagination
  65. background
  66. :current-page="cur_page"
  67. :page-sizes="[10, 20, 30, 40, 50]"
  68. :page-size="page_capacity"
  69. layout="total, prev, pager, next, sizes, jumper"
  70. :total="total_count"
  71. @prev-click="changePage"
  72. @next-click="changePage"
  73. @current-change="changePage"
  74. @size-change="changePageSize"
  75. />
  76. <ListingDialog :id="curId" :visible.sync="dialogVisible" @PublishSuccess="publishSuccess" />
  77. </div>
  78. </template>
  79. <script>
  80. import ListingDialog from './components/ListingDialog.vue';
  81. import { PageQueryBookList, GetBookCreatorList, SetPublishStatusForBook, DeleteBook } from '@/api/book';
  82. export default {
  83. name: 'HomePage',
  84. components: {
  85. ListingDialog,
  86. },
  87. data() {
  88. return {
  89. data: undefined,
  90. name: '',
  91. creator_id: '',
  92. cur_page: 1,
  93. page_capacity: 10,
  94. total_count: 0,
  95. publish_status: 1,
  96. user_list: [],
  97. publishStatusList: [
  98. {
  99. label: '已上架',
  100. value: 1,
  101. },
  102. {
  103. label: '草稿',
  104. value: 0,
  105. },
  106. ],
  107. curId: '',
  108. dialogVisible: false,
  109. };
  110. },
  111. watch: {
  112. publish_status: {
  113. handler() {
  114. this.pageQueryBookList();
  115. },
  116. },
  117. },
  118. created() {
  119. GetBookCreatorList().then(({ user_list }) => {
  120. this.user_list = user_list;
  121. });
  122. this.pageQueryBookList();
  123. },
  124. methods: {
  125. createBook() {
  126. this.$router.push('/book/create');
  127. },
  128. changePage(number) {
  129. this.cur_page = number;
  130. this.pageQueryBookList();
  131. },
  132. changePageSize(size) {
  133. this.page_capacity = size;
  134. this.pageQueryBookList();
  135. },
  136. // 分页查询教材列表
  137. pageQueryBookList() {
  138. PageQueryBookList({
  139. name: this.name,
  140. creator_id: this.creator_id,
  141. cur_page: this.cur_page,
  142. page_capacity: this.page_capacity,
  143. sys_version_type: 1,
  144. publish_status: this.publish_status,
  145. }).then(({ book_list, total_count }) => {
  146. this.data = book_list;
  147. this.total_count = total_count;
  148. });
  149. },
  150. /**
  151. * 编辑教材
  152. * @param {string} book_id 教材id
  153. */
  154. editBook(book_id) {
  155. this.$router.push(`/book/create?book_id=${book_id}`);
  156. },
  157. /**
  158. * 上架教材
  159. * @param {string} id 教材id
  160. */
  161. listingBook(id) {
  162. this.dialogVisible = true;
  163. this.curId = id;
  164. },
  165. // 下架教材
  166. setUnpublishForBook(book_id) {
  167. SetPublishStatusForBook({ book_id, publish_status: 0, publish_scope: 0 }).then(() => {
  168. this.pageQueryBookList();
  169. });
  170. },
  171. /**
  172. * 上架成功事件
  173. */
  174. publishSuccess() {
  175. this.pageQueryBookList();
  176. const div = document.createElement('div');
  177. div.style.cssText = `
  178. width: 227px;
  179. height: 212px;
  180. border-radius: 12px;
  181. background-color: #4ABB38;
  182. position: fixed;
  183. top: 20%;
  184. left: calc(50% - 113px);
  185. display: flex;
  186. flex-direction: column;
  187. row-gap: 32px;
  188. justify-content: center;
  189. align-items: center;
  190. color: #fff;
  191. `;
  192. const check = document.createElement('div');
  193. check.style.cssText = `
  194. width: 50px;
  195. height: 25px;
  196. border-bottom: 4px solid #fff;
  197. border-left: 4px solid #fff;
  198. transform: rotate(-45deg);
  199. `;
  200. div.appendChild(check);
  201. const span = document.createElement('span');
  202. span.innerHTML = '上架成功';
  203. div.appendChild(span);
  204. document.body.appendChild(div);
  205. setTimeout(() => {
  206. document.body.removeChild(div);
  207. }, 1000);
  208. },
  209. /**
  210. * 删除教材
  211. * @param {string} id 教材id
  212. */
  213. deleteBook(id) {
  214. this.$confirm('是否删除该教材?', '提示', {
  215. confirmButtonText: '确定',
  216. cancelButtonText: '取消',
  217. type: 'warning',
  218. })
  219. .then(() => {
  220. DeleteBook({ id, is_force_delete: 'true' }).then(() => {
  221. this.pageQueryBookList();
  222. });
  223. })
  224. .catch(() => {});
  225. },
  226. },
  227. };
  228. </script>
  229. <style lang="scss" scoped>
  230. .home {
  231. display: flex;
  232. flex-direction: column;
  233. row-gap: 16px;
  234. min-height: calc(100% - 16px);
  235. padding: 24px;
  236. margin: 0 24px 16px;
  237. background-color: #fff;
  238. border-radius: 4px;
  239. &-title {
  240. display: flex;
  241. justify-content: space-between;
  242. &:first-child {
  243. font-size: 20px;
  244. font-weight: bold;
  245. }
  246. }
  247. &-tabs {
  248. display: flex;
  249. column-gap: 10px;
  250. .tab-item {
  251. padding: 5px 16px;
  252. font-size: 14px;
  253. cursor: pointer;
  254. border-radius: 16px;
  255. &.active {
  256. font-weight: bold;
  257. color: $main-color;
  258. background-color: $fill-color;
  259. }
  260. }
  261. }
  262. .search {
  263. display: grid;
  264. grid-template-rows: 30px 32px;
  265. grid-template-columns: repeat(2, 200px);
  266. grid-auto-flow: column;
  267. column-gap: 24px;
  268. &-name {
  269. font-size: 14px;
  270. color: $font-light-color;
  271. }
  272. }
  273. }
  274. </style>