step-two.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <div class="edit-content">
  3. <div class="edit-form">
  4. <div class="edit-form-item">
  5. <p class="edit-label">正文</p>
  6. <div class="charpt-list form-content">
  7. <template v-for="(item, idx) in charptList" :key="idx">
  8. <div class="charpt-list-item">
  9. <p class="item-label">文章标题</p>
  10. <div class="item-input">
  11. <a-input
  12. v-model:value="item.title"
  13. placeholder="请输入标题"
  14. style="width:638px"
  15. />
  16. </div>
  17. <a
  18. href="javascript:;"
  19. class="delete-text"
  20. v-show="idx > 0"
  21. @click="deleteLine(idx)"
  22. >删除</a
  23. >
  24. </div>
  25. <div class="charpt-list-item bor-line">
  26. <p class="item-label">正文内容</p>
  27. <div class="item-input">
  28. <a-textarea
  29. v-model:value="item.content"
  30. placeholder="请输入正文"
  31. :auto-size="{ minRows: 5, maxRows: 10 }"
  32. />
  33. </div>
  34. </div>
  35. <hr />
  36. </template>
  37. <div class="add-item" @click="addNewCharpt">
  38. 添加新章节+
  39. </div>
  40. </div>
  41. </div>
  42. <div class="edit-form-item">
  43. <p class="edit-label">顶部图片</p>
  44. <div class="choose-img">
  45. <div v-show="!selectImg" class="black-chos" @click="showModel">
  46. 选择
  47. </div>
  48. <div class="img" v-show="selectImg">
  49. <img :src="chooseImgUrl" style="width:100%" @click="showModel" />
  50. </div>
  51. </div>
  52. </div>
  53. <div class="edit-form-item">
  54. <p class="edit-label">正文模板</p>
  55. <div class="template-list">
  56. <div
  57. v-for="(item, index) in templateList"
  58. v-html="item.content"
  59. :key="index"
  60. :class="[
  61. 'template-item',
  62. index == templateChecked ? 'current' : '',
  63. ]"
  64. @click="chooseTemplate(item, index)"
  65. ></div>
  66. </div>
  67. </div>
  68. </div>
  69. <a-modal
  70. v-model:visible="modelShow"
  71. title="顶部图片"
  72. @ok="handleSumbit"
  73. :width="1000"
  74. >
  75. <a-tabs v-model:activeKey="activeKey" @change="loadMore(1, true)">
  76. <a-tab-pane key="10" tab="女频"></a-tab-pane>
  77. <a-tab-pane key="11" tab="男频"></a-tab-pane>
  78. <a-tab-pane key="12" tab="活动"></a-tab-pane>
  79. </a-tabs>
  80. <div class="radio-grouped">
  81. <a-radio-group
  82. v-model:value="chooseType"
  83. style="margin: 0 auto"
  84. @change="loadMore(1, true)"
  85. >
  86. <a-radio-button value="1">现代</a-radio-button>
  87. <a-radio-button value="2">古代</a-radio-button>
  88. </a-radio-group>
  89. </div>
  90. <a-list
  91. class="loadmore-list"
  92. :loading="listLoading"
  93. item-layout="horizontal"
  94. :grid="{ gutter: 10, xs: 1, sm: 2, md: 4, lg: 4, xl: 6, xxl: 6 }"
  95. :data-source="dataList"
  96. >
  97. <template #loadMore>
  98. <div
  99. :style="{
  100. textAlign: 'center',
  101. marginTop: '12px',
  102. height: '32px',
  103. lineHeight: '32px',
  104. }"
  105. >
  106. <a-button
  107. v-show="!listLoading && showLoaderMore"
  108. @click="loadMore()"
  109. >加载更多</a-button
  110. >
  111. </div>
  112. </template>
  113. <template #renderItem="{ item, index }">
  114. <a-list-item>
  115. <div :class="['img-item', index == temChecked ? 'current' : '']">
  116. <a-popover title="预览" trigger="click">
  117. <template #content>
  118. <img :src="item.link" />
  119. </template>
  120. <img :src="item.link" @click="chooseImg(item, index)" />
  121. </a-popover>
  122. </div>
  123. </a-list-item>
  124. </template>
  125. </a-list>
  126. </a-modal>
  127. </div>
  128. </template>
  129. <script lang="ts">
  130. import { defineComponent, reactive, ref, toRefs, onMounted } from "vue";
  131. import { getLandingPic, getLandingTempalte } from "@/api";
  132. const StepTwo = defineComponent({
  133. name: "StepTwo",
  134. setup(props, { emit }) {
  135. const state = reactive({
  136. charptList: ref<Array<{ content: string; title: string }>>([
  137. {
  138. title: "大苏打萨达速度阿萨德阿萨德阿士大夫撒方式打发的撒范德萨飞",
  139. content: "sadassssssssssssssssasdsaddasdas",
  140. },
  141. ]),
  142. modelShow: false,
  143. selectImg: false,
  144. activeKey: "10",
  145. chooseType: "1",
  146. currentPage: 1,
  147. listLoading: false,
  148. showLoaderMore: true,
  149. dataList: [],
  150. chooseImgUrl: "",
  151. temItem: ref<any>({}),
  152. temChecked: ref<any>(null),
  153. templateItemChecked: ref<any>({}),
  154. templateChecked: ref<any>(null),
  155. templateList: ref<any[]>([]),
  156. });
  157. const addNewCharpt = () => {
  158. let data = {
  159. title: "",
  160. content: "",
  161. };
  162. state.charptList.push(data);
  163. };
  164. const deleteLine = (idx: number) => {
  165. state.charptList.splice(idx, 1);
  166. };
  167. //弹窗
  168. const showModel = () => {
  169. state.modelShow = true;
  170. loadMore();
  171. };
  172. //选择图片
  173. const chooseImg = (item: any, idx: number) => {
  174. state.temItem = item;
  175. state.temChecked = idx;
  176. };
  177. onMounted(() => {
  178. getTemList();
  179. });
  180. //模板列表
  181. const getTemList = () => {
  182. getLandingTempalte().then((res: any) => {
  183. state.templateList = res.data.list;
  184. });
  185. };
  186. //选择正文模板
  187. const chooseTemplate = (item: any, index: number) => {
  188. state.templateItemChecked = item;
  189. state.templateChecked = index;
  190. };
  191. //加载更多
  192. const loadMore = (page?: number, clear?: boolean) => {
  193. if (clear) {
  194. state.temItem = {};
  195. state.temChecked = null;
  196. state.dataList = [];
  197. }
  198. getLandingPic(
  199. state.activeKey,
  200. state.chooseType,
  201. page ?? state.currentPage
  202. ).then((res: any) => {
  203. state.dataList = state.dataList.concat(res.data.list);
  204. state.currentPage = res.data.meta.current_page + 1;
  205. if (res.data.meta.is_end) state.showLoaderMore = false;
  206. });
  207. };
  208. //选择顶部图
  209. const handleSumbit = () => {
  210. state.chooseImgUrl = state.temItem.link;
  211. state.selectImg = true;
  212. state.modelShow = false;
  213. };
  214. return {
  215. ...toRefs(state),
  216. addNewCharpt,
  217. deleteLine,
  218. handleSumbit,
  219. showModel,
  220. loadMore,
  221. chooseImg,
  222. chooseTemplate,
  223. };
  224. },
  225. });
  226. export default StepTwo;
  227. </script>
  228. <style lang="scss" scoped>
  229. .loadmore-list {
  230. margin-top: 30px;
  231. .img-item {
  232. width: 144px;
  233. height: 144px;
  234. background: #ffffff;
  235. border-radius: 6px;
  236. overflow: hidden;
  237. position: relative;
  238. image {
  239. width: 144px;
  240. }
  241. &.current {
  242. border: 2px solid #006eff;
  243. &::after {
  244. position: absolute;
  245. width: 0;
  246. height: 0;
  247. border-top: 20px solid #006eff;
  248. border-left: 20px solid transparent;
  249. display: block;
  250. content: "";
  251. top: 0;
  252. right: 0;
  253. }
  254. }
  255. }
  256. }
  257. .template-list {
  258. width: 726px;
  259. height: 366px;
  260. background: #f7f7f7;
  261. max-height: 366px;
  262. overflow-y: scroll;
  263. position: relative;
  264. padding: 24px 110px;
  265. .template-item {
  266. margin: 25px 0;
  267. background: #fff;
  268. position: relative;
  269. &.current {
  270. border-radius: 6px;
  271. border: 2px solid #006eff;
  272. &::after {
  273. display: block;
  274. content: "";
  275. position: absolute;
  276. right: 8px;
  277. top: 8px;
  278. width: 20px;
  279. height: 20px;
  280. z-index: 10;
  281. background-image: url('../../../../assets/checked.png');
  282. background-repeat: no-repeat;
  283. background-size: cover;
  284. }
  285. }
  286. }
  287. }
  288. .choose-img {
  289. .img {
  290. width: 144px;
  291. height: 144px;
  292. overflow: hidden;
  293. line-height: 144px;
  294. image {
  295. display: inline-block;
  296. vertical-align: middle;
  297. line-height: initial;
  298. }
  299. }
  300. }
  301. .radio-grouped {
  302. text-align: center;
  303. }
  304. .edit-form {
  305. .add-item {
  306. width: 270px;
  307. height: 40px;
  308. line-height: 35px;
  309. color: #006eff;
  310. font-size: 14px;
  311. text-align: center;
  312. background: #ffffff;
  313. border-radius: 3px;
  314. border: 2px solid #006eff;
  315. margin: 15px auto 0;
  316. }
  317. .edit-form-item {
  318. font-size: 14px;
  319. display: flex;
  320. align-items: center;
  321. margin-bottom: 40px;
  322. .black-chos {
  323. background-color: #f7f7f7;
  324. width: 100px;
  325. height: 100px;
  326. text-align: center;
  327. line-height: 100px;
  328. color: #d8d8d8;
  329. }
  330. hr {
  331. margin-bottom: 25px;
  332. border: none;
  333. height: 1px;
  334. background-color: #e5e5e5;
  335. }
  336. .edit-label {
  337. margin-right: 15px;
  338. width: 100px;
  339. }
  340. .form-content {
  341. padding: 30px 50px;
  342. background: #f7f7f7;
  343. }
  344. .charpt-list-item {
  345. display: flex;
  346. align-items: center;
  347. margin-bottom: 30px;
  348. overflow: hidden;
  349. &.bor-line {
  350. margin-bottom: 25px;
  351. }
  352. .item-label {
  353. margin-right: 18px;
  354. }
  355. .delete-text {
  356. display: block;
  357. margin-left: 15px;
  358. }
  359. }
  360. }
  361. }
  362. </style>
  363. <style lang="scss">
  364. .bor-line {
  365. .item-input {
  366. textarea {
  367. width: 638px;
  368. }
  369. }
  370. }
  371. </style>