小说后台管理系统
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

317 lines
8.3 KiB

  1. <template>
  2. <div class="home-box">
  3. <el-main>
  4. <ActionButton @handle-refresh="refreshData" />
  5. <div class="mod-title">Banner模块</div>
  6. <div class="banner-box">
  7. <el-table ref="dataList" :data="banner">
  8. <el-table-column label="序号" type="index" width="80" align="center">
  9. </el-table-column>
  10. <el-table-column label="名称" align="center">
  11. <template slot-scope="scope">
  12. <el-input placeholder="请输入名称" v-model="scope.row.name"></el-input>
  13. </template>
  14. </el-table-column>
  15. <el-table-column label="书籍" align="center">
  16. <template slot-scope="scope">
  17. <el-button
  18. type="primary"
  19. icon="el-icon-edit"
  20. size="mini"
  21. @click="onBooksAdd(scope.$index)"
  22. ></el-button>
  23. <el-tag style="margin-left: 10px" v-if="scope.row.value">{{
  24. scope.row.book_info.book_name
  25. }}</el-tag>
  26. </template>
  27. </el-table-column>
  28. <el-table-column label="状态" align="center" show-overflow-tooltip>
  29. <template slot-scope="scope">
  30. <el-switch
  31. v-model="scope.row.status"
  32. :active-value="1"
  33. :inactive-value="0"
  34. ></el-switch>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="操作" align="center">
  38. <template slot-scope="scope">
  39. <div class="flex-box">
  40. <CustomButton
  41. tip-text="删除"
  42. type="danger"
  43. is-svg
  44. icon="delete"
  45. @onClick="onDeleteBanner(scope.$index)"
  46. />
  47. </div>
  48. </template>
  49. </el-table-column>
  50. </el-table>
  51. <el-button
  52. style="margin: 15px 0 15px 30px"
  53. type="primary"
  54. icon="el-icon-plus"
  55. size="mini"
  56. @click="onPushBanner"
  57. >模块</el-button
  58. >
  59. </div>
  60. <div class="mod-title">书籍展示模块</div>
  61. <div class="banner-box">
  62. <el-table ref="dataList" :data="book_show">
  63. <el-table-column label="序号" type="index" width="80" align="center">
  64. </el-table-column>
  65. <el-table-column label="书籍标题" align="center">
  66. <template slot-scope="scope">
  67. <el-input placeholder="请输入名称" v-model="scope.row.name"></el-input>
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="排列样式" align="center">
  71. <template slot-scope="scope">
  72. <el-select v-model="scope.row.value.style" placeholder="请选择">
  73. <el-option
  74. v-for="item in options"
  75. :key="item.value"
  76. :label="item.label"
  77. :value="item.value"
  78. >
  79. </el-option>
  80. </el-select>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="书籍分类" align="center">
  84. <template slot-scope="scope">
  85. <el-select
  86. v-model.number="scope.row.value.category_id"
  87. placeholder="请选择"
  88. >
  89. <el-option
  90. v-for="item in booksData"
  91. :key="item.value"
  92. :label="item.category_name"
  93. :value="item.id"
  94. >
  95. </el-option>
  96. </el-select>
  97. </template>
  98. </el-table-column>
  99. <el-table-column label="状态" align="center" show-overflow-tooltip>
  100. <template slot-scope="scope">
  101. <el-switch
  102. v-model="scope.row.status"
  103. :active-value="1"
  104. :inactive-value="0"
  105. ></el-switch>
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="操作" align="center">
  109. <template slot-scope="scope">
  110. <div class="flex-box">
  111. <CustomButton
  112. tip-text="删除"
  113. type="danger"
  114. is-svg
  115. icon="delete"
  116. @onClick="onDeleteBook(scope.$index)"
  117. />
  118. </div>
  119. </template>
  120. </el-table-column>
  121. </el-table>
  122. <div>
  123. <el-button
  124. style="margin: 15px 0 15px 30px"
  125. type="primary"
  126. icon="el-icon-plus"
  127. size="mini"
  128. @click="onPushBook"
  129. >模块</el-button
  130. >
  131. <el-tooltip content="最多添加8个模块" placement="top" effect="light">
  132. <i class="el-icon-question" style="color: #3da2ff; margin-left: 10px"></i>
  133. </el-tooltip>
  134. </div>
  135. </div>
  136. <el-footer height="10%">
  137. <el-button type="primary" style="margin-right: 27px" @click="submitForm"
  138. >保存</el-button
  139. >
  140. <el-button type="info" plain @click="resetForm('selectItem')">重置</el-button>
  141. </el-footer>
  142. </el-main>
  143. <BooksDialog
  144. :isBooksShow="isBooksShow"
  145. @onSelectItem="onSelectItem"
  146. @handle-close="isBooksShow = false"
  147. :booksData="booksData"
  148. ></BooksDialog>
  149. </div>
  150. </template>
  151. <script>
  152. import ActionButton from "@/components/ActionButton/index";
  153. import CustomButton from "@/components/CustomButton/index";
  154. import BooksDialog from "./books-dialog/books-dialog";
  155. import { getCategoryList } from "@/api/sort-management";
  156. import { getHomePage, homeSetting } from "@/api/home";
  157. getHomePage;
  158. export default {
  159. components: {
  160. ActionButton,
  161. CustomButton,
  162. BooksDialog,
  163. },
  164. data() {
  165. return {
  166. selectIndex: null,
  167. isBooksShow: false,
  168. banner: [],
  169. book_show: [],
  170. booksData: [],
  171. options: [
  172. {
  173. value: "1",
  174. label: "竖向排列",
  175. },
  176. {
  177. value: "2",
  178. label: "横向排列",
  179. },
  180. ],
  181. };
  182. },
  183. mounted() {
  184. this.init();
  185. this.openCheckBooksDialog();
  186. },
  187. methods: {
  188. // 初始化
  189. init() {
  190. getHomePage().then((res) => {
  191. if (res.data.banner) {
  192. this.banner = res.data.banner;
  193. this.book_show = res.data.book_show;
  194. } else {
  195. this.book_show = [
  196. {
  197. name: "",
  198. value: { style: "", category_id: "" },
  199. status: "",
  200. },
  201. {
  202. name: "",
  203. value: { style: "", category_id: "" },
  204. status: "",
  205. },
  206. ];
  207. this.banner = [
  208. { name: "", value: "", status: "" },
  209. { name: "", value: "", status: "" },
  210. ];
  211. }
  212. });
  213. },
  214. /**
  215. * 添加书籍
  216. */
  217. onBooksAdd(i) {
  218. this.isBooksShow = true;
  219. this.selectIndex = i;
  220. },
  221. onSelectItem(data) {
  222. this.isBooksShow = false;
  223. this.banner[this.selectIndex].value = data.book_id;
  224. this.banner[this.selectIndex].book_info = data;
  225. },
  226. // 删除banner
  227. onDeleteBanner(i) {
  228. this.banner.splice(i, 1);
  229. },
  230. onDeleteBook(i) {
  231. this.book_show.splice(i, 1);
  232. },
  233. // 刷新
  234. refreshData() {
  235. console.log("刷新");
  236. },
  237. // 打开查看书籍弹窗
  238. openCheckBooksDialog() {
  239. this.booksData = [];
  240. getCategoryList({
  241. source_platform: "1",
  242. need_num: true,
  243. }).then((res) => {
  244. this.booksData = res.data; // 分类列表
  245. });
  246. },
  247. onPushBanner() {
  248. this.banner.push({
  249. name: "",
  250. value: "",
  251. status: "",
  252. });
  253. },
  254. onPushBook() {
  255. this.book_show.push({
  256. name: "",
  257. value: { style: "", category_id: "" },
  258. status: "",
  259. });
  260. },
  261. submitForm() {
  262. homeSetting({
  263. book_show: this.book_show,
  264. banner: this.banner,
  265. }).then((res) => {
  266. this.init();
  267. this.$message.success("保存成功");
  268. });
  269. },
  270. resetForm() {
  271. this.init();
  272. },
  273. },
  274. };
  275. </script>
  276. <style lang="scss" scoped>
  277. .mod-title {
  278. color: #333333;
  279. font-size: 14px;
  280. font-weight: bold;
  281. }
  282. .banner-box {
  283. background: #ffffff;
  284. border-radius: 10px;
  285. border: 1px solid #e3e3e3;
  286. width: 100%;
  287. box-sizing: border-box;
  288. padding: 20px;
  289. margin: 12px 0 20px;
  290. }
  291. </style>