carousel.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <script>
  2. import axios from "axios";
  3. import {defineComponent} from "vue";
  4. import RoundedTitle from "../../../components/public/roundedTitle.vue";
  5. import {rCode} from "../../../map/rcodeMap_esm";
  6. import handle from "../../../until/handle";
  7. import ImageViewer from "../../../components/public/imageViewer.vue";
  8. import ImageTable from "../../../components/public/imageTable.vue";
  9. import Pop from "../../../components/public/pop.vue";
  10. import PopCard from "../../../components/public/popCard.vue";
  11. export default defineComponent({
  12. name: 'carousel',
  13. components: {PopCard, Pop, ImageTable, ImageViewer, RoundedTitle},
  14. async asyncData(ctx){
  15. // 加载轮播图数据
  16. let [err,res] = await handle(axios.get('/api/base/carousel'));
  17. if(err){
  18. return {};
  19. }
  20. let result = res.data;
  21. if(result.code === rCode.OK){
  22. return {carouselList: result.data}
  23. }else{
  24. this.$message.error(result.msg);
  25. return {}
  26. }
  27. return {}
  28. },
  29. data(){
  30. return {
  31. loading: false,
  32. carouselList: [],
  33. popShow: false,
  34. popLoading: false,
  35. carouselPopShow: true,
  36. carouselPopLoading: false,
  37. isEditCarousel: false,
  38. }
  39. },
  40. mounted() {
  41. if(this.carouselList.length === 0){
  42. this.getCarouselList();
  43. }
  44. },
  45. methods: {
  46. async getCarouselList(){
  47. this.loading = true;
  48. let [err,res] = await handle(this.$axios.get('/api/base/carousel'));
  49. this.loading = false;
  50. if(err){
  51. if(this.NotificationKey){
  52. this.$notification.close(this.NotificationKey);
  53. }
  54. this.NotificationKey = `open${Date.now()}`;
  55. return this.$notification.error({
  56. message: '轮播数据加载失败',
  57. description:`异常: ${err.message}`,
  58. duration: 0,
  59. btn: h => {
  60. return h(
  61. 'a-button',
  62. {
  63. props: {
  64. type: 'primary',
  65. size: 'small',
  66. },
  67. on: {
  68. click: () => {
  69. this.$notification.close(this.NotificationKey);
  70. this.getCarouselList();
  71. },
  72. },
  73. },
  74. '重试',
  75. );
  76. },
  77. key:this.NotificationKey,
  78. onClose: close,
  79. });
  80. }
  81. let result = res.data;
  82. if(result.code === rCode.OK){
  83. this.carouselList = result.data;
  84. return {carouselList: result.data}
  85. }else{
  86. this.$message.error(result.msg);
  87. return {}
  88. }
  89. },
  90. async addCarouselItem(){
  91. // 打开弹窗. 选择图片,填写链接地址,排序
  92. },
  93. showPop(){
  94. this.popShow = true;
  95. this.popLoading = false;
  96. },
  97. cancelPop(){
  98. this.popShow = false;
  99. this.popLoading = false;
  100. },
  101. okHandle(fileItem){
  102. console.log(fileItem);
  103. this.cancelPop();
  104. }
  105. },
  106. })
  107. </script>
  108. <template>
  109. <div class="w-full p-2">
  110. <rounded-title>轮播图管理</rounded-title>
  111. <div class="mt-2 rounded bg-white p-2">
  112. <!-- 轮播图list , 左侧轮播图片, 右侧 轮播信息 -->
  113. <div class="mt-2 rounded bg-white p-2">
  114. <div class="py-1 border-b border-cyan-300 flex justify-between">
  115. 点击下方快进行管理轮播图数据,一次性不要添加过多轮播图
  116. <!-- 新增按钮-->
  117. <a-button type="primary" class="ant-icon-btn" icon="plus" @click="addCarouselItem" :loading="loading"></a-button>
  118. <!-- 刷新按钮-->
  119. <a-button type="primary" class="ant-icon-btn" icon="reload" @click="getCarouselList" :loading="loading"></a-button>
  120. </div>
  121. <div class="w-full h-auto transition">
  122. <div v-show="loading" class="w-full h-64 flex justify-center items-center ">
  123. <a-spin size="large" />
  124. </div>
  125. <div
  126. v-for="(item,index) in carouselList"
  127. :key="'carouse-'+index"
  128. class="mt-2 rounded border flex h-72 overflow-hidden"
  129. >
  130. <div class="media w-1/2 h-full">
  131. <image-viewer :src="item.filePath"></image-viewer>
  132. </div>
  133. <div class="w-1/2 h-full box-border pl-2">
  134. <a-button @click="showPop">编辑</a-button>
  135. 排序{{item.sort}},数字越小越靠前
  136. 链接地址: {{item.href}}
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. <pop :show="popShow" :loading="popLoading">
  143. <image-table @cancel="cancelPop" @ok="okHandle"></image-table>
  144. <!-- <choose-to-sit></choose-to-sit>-->
  145. </pop>
  146. <pop :show="carouselPopShow" :loading="carouselPopLoading">
  147. <pop-card>
  148. <template slot="header" class="w-full">
  149. {{isEditCarousel ? '编辑轮播图' : '新增轮播图'}}
  150. </template>
  151. <template slot="close-group">取消</template>
  152. <div class="w-full">
  153. 内容
  154. </div>
  155. <template class="w-full" slot="footer">
  156. <a-button>{{isEditCarousel? '保存': '新增'}}</a-button>
  157. </template>
  158. </pop-card>
  159. </pop>
  160. </div>
  161. </template>
  162. <style scoped>
  163. </style>