swiperBg.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <!-- 带背景轮播图 -->
  3. <common-wrapper :config="configData">
  4. <view class="swiperBg">
  5. <template v-if="dataConfig.swiperConfig.list.length">
  6. <view class="swiper">
  7. <swiper
  8. :style="'height:' + imageH + 'rpx;'"
  9. :autoplay="true"
  10. :previous-margin="swiperMargin"
  11. :next-margin="swiperMargin"
  12. :circular="circular"
  13. :interval="interval"
  14. :duration="duration"
  15. @change="bannerfun"
  16. v-if="imageH"
  17. >
  18. <swiper-item
  19. v-for="(item, index) in dataConfig.swiperConfig.list"
  20. :key="index"
  21. >
  22. <view
  23. @click="goDetail(item)"
  24. class="swiper-item"
  25. :style="[itemStyle, active == index ? activeStyle : '']"
  26. >
  27. <image
  28. :src="item.img"
  29. mode="aspectFill"
  30. class="image"
  31. :style="[imageStyle]"
  32. ></image>
  33. </view>
  34. </swiper-item>
  35. </swiper>
  36. <view class="noPic" v-else>{{ $t(`图片加载中`) }}...</view>
  37. <view class="dot acea-row" :style="[dotStyle]">
  38. <view
  39. class="progress"
  40. v-if="dataConfig.docConfig.tabVal == 2"
  41. :style="[progressWidth, dotItemStyle]"
  42. >
  43. <view
  44. class="inner"
  45. :style="[progressValue, dotItemActiveStyle]"
  46. ></view>
  47. </view>
  48. <view
  49. class="acea-row"
  50. :class="{
  51. small: dataConfig.docConfig.tabVal == 1,
  52. line: dataConfig.docConfig.tabVal == 3,
  53. }"
  54. v-else
  55. >
  56. <view
  57. class="dot-item"
  58. v-for="(item, index) in dataConfig.swiperConfig.list"
  59. :key="index"
  60. :class="{ active: active == index }"
  61. :style="[active == index ? dotItemActiveStyle : dotItemStyle]"
  62. ></view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. </view>
  68. </common-wrapper>
  69. </template>
  70. <script>
  71. import commonWrapper from "./commonWrapper.vue";
  72. export default {
  73. components: { commonWrapper },
  74. name: "swiperBg",
  75. props: {
  76. dataConfig: {
  77. type: Object,
  78. default: () => {},
  79. },
  80. isSortType: {
  81. type: String | Number,
  82. default: 0,
  83. },
  84. },
  85. data() {
  86. return {
  87. circular: true,
  88. autoplay: true,
  89. interval: 3000,
  90. duration: 500,
  91. imgUrls: [], //图片轮播数据
  92. bgColor: "", //轮播背景颜色
  93. marginTop: 0, //组件上边距
  94. paddinglr: 0, //轮播左右边距
  95. docConfig: 0, //指示点样式
  96. imgConfig: 0, //是否为圆角
  97. imageH: 0,
  98. isColor: 0,
  99. txtStyle: 0,
  100. dotColor: "",
  101. current: 1, //数字指示器当前
  102. active: 0, //一般指示器当前
  103. swiperMargin: "",
  104. };
  105. },
  106. computed: {
  107. configData() {
  108. return {
  109. ...this.dataConfig,
  110. paddingConfig: this.dataConfig.paddingConfig || {
  111. isAll: false,
  112. valList: [
  113. {
  114. val: this.dataConfig.topConfig
  115. ? this.dataConfig.topConfig.val
  116. : 0,
  117. },
  118. {
  119. val: this.dataConfig.prConfig ? this.dataConfig.prConfig.val : 0,
  120. },
  121. {
  122. val: this.dataConfig.bottomConfig
  123. ? this.dataConfig.bottomConfig.val
  124. : 0,
  125. },
  126. {
  127. val: this.dataConfig.prConfig ? this.dataConfig.prConfig.val : 0,
  128. },
  129. ],
  130. },
  131. marginConfig: this.dataConfig.marginConfig || {
  132. isAll: false,
  133. valList: [
  134. {
  135. val: this.dataConfig.mbConfig ? this.dataConfig.mbConfig.val : 0,
  136. },
  137. {
  138. val: 0,
  139. },
  140. {
  141. val: 0,
  142. },
  143. {
  144. val: 0,
  145. },
  146. ],
  147. },
  148. };
  149. },
  150. itemStyle() {
  151. let val = this.dataConfig.imgConfig.val;
  152. let num = 1;
  153. if (this.dataConfig.styleConfig.tabVal == 1) {
  154. num = !val ? 1 : 0.9;
  155. }
  156. return {
  157. transform: `scale(${num})`,
  158. };
  159. },
  160. activeStyle() {
  161. let val = this.dataConfig.imgConfig.val;
  162. let num = 1;
  163. if (this.dataConfig.styleConfig.tabVal == 1) {
  164. num = !val ? 1 : 1 - val / 400;
  165. }
  166. return {
  167. transform: `scale(${num})`,
  168. };
  169. },
  170. // colorBgStyle() {
  171. // let styleObject = {
  172. // background: this.dataConfig.bgColor.color[0].item,
  173. // };
  174. // if (this.dataConfig.styleConfig.tabVal == 1) {
  175. // styleObject["height"] = "50%";
  176. // }
  177. // return styleObject;
  178. // },
  179. imageStyle() {
  180. let borderRadius = `${this.dataConfig.filletImg.val * 2}rpx`;
  181. if (this.dataConfig.filletImg.type) {
  182. borderRadius = `${this.dataConfig.filletImg.valList[0].val * 2}rpx ${
  183. this.dataConfig.filletImg.valList[1].val * 2
  184. }rpx ${this.dataConfig.filletImg.valList[3].val * 2}rpx ${
  185. this.dataConfig.filletImg.valList[2].val * 2
  186. }rpx`;
  187. }
  188. return {
  189. borderRadius: borderRadius,
  190. };
  191. },
  192. dotStyle() {
  193. let styleObject = {};
  194. if (this.dataConfig.docPosition.tabVal) {
  195. styleObject["justify-content"] =
  196. this.dataConfig.docPosition.tabVal == 1 ? "center" : "flex-end";
  197. }
  198. if (this.dataConfig.styleConfig.tabVal == 1) {
  199. styleObject["padding"] = "0 100rpx";
  200. styleObject["bottom"] = "32rpx";
  201. }
  202. return styleObject;
  203. },
  204. dotItemStyle() {
  205. let styleObject = {};
  206. if (this.dataConfig.toneConfig.tabVal) {
  207. styleObject["background"] = this.dataConfig.dotBgColor.color[0].item;
  208. }
  209. return styleObject;
  210. },
  211. dotItemActiveStyle() {
  212. let styleObject = {};
  213. if (this.dataConfig.toneConfig.tabVal) {
  214. styleObject["background"] = this.dataConfig.dotColor.color[0].item;
  215. }
  216. return styleObject;
  217. },
  218. progressWidth() {
  219. return {
  220. width: `${this.dataConfig.swiperConfig.list.length * 20}rpx`,
  221. };
  222. },
  223. progressValue() {
  224. return {
  225. width: `${
  226. (this.current / this.dataConfig.swiperConfig.list.length) * 100
  227. }%`,
  228. };
  229. },
  230. },
  231. watch: {
  232. imageH(nVal, oVal) {
  233. let self = this;
  234. this.imageH = nVal;
  235. },
  236. },
  237. created() {
  238. this.imgUrls = this.dataConfig.swiperConfig.list;
  239. if (this.dataConfig.styleConfig.tabVal == 1) {
  240. this.swiperMargin = "55rpx";
  241. }
  242. },
  243. mounted() {
  244. if (this.imgUrls.length) {
  245. let that = this;
  246. this.$nextTick((e) => {
  247. uni.getImageInfo({
  248. src: that.setDomain(that.imgUrls[0].img),
  249. success: (res) => {
  250. if (res && res.height > 0) {
  251. let p = this.dataConfig.paddingConfig.isAll
  252. ? this.dataConfig.paddingConfig.val
  253. : this.dataConfig.paddingConfig.valList[1].val;
  254. let height = res.height * ((750 - p * 4) / res.width);
  255. that.$set(that, "imageH", height);
  256. } else {
  257. that.$set(that, "imageH", 375);
  258. }
  259. },
  260. fail: function (error) {
  261. that.$set(that, "imageH", 375);
  262. },
  263. });
  264. });
  265. }
  266. },
  267. methods: {
  268. bannerfun(e) {
  269. this.active = e.detail.current;
  270. this.current = e.detail.current + 1;
  271. },
  272. //替换安全域名
  273. setDomain: function (url) {
  274. url = url ? url.toString() : "";
  275. //本地调试打开,生产请注销
  276. if (url.indexOf("https://") > -1) return url;
  277. else return url.replace("http://", "https://");
  278. },
  279. goDetail(url) {
  280. let urls = url.info[0].value;
  281. this.$util.JumpPath(urls);
  282. },
  283. },
  284. };
  285. </script>
  286. <style lang="scss">
  287. .noPic {
  288. border-radius: 10rpx;
  289. width: 100%;
  290. height: 300rpx;
  291. background-color: #f0f0f0;
  292. color: #ccc;
  293. text-align: center;
  294. line-height: 300rpx;
  295. font-size: 30rpx;
  296. }
  297. .swiperBg {
  298. position: relative;
  299. .colorBg {
  300. position: absolute;
  301. left: 0;
  302. top: 0;
  303. height: 100%;
  304. width: 100%;
  305. }
  306. .swiper {
  307. z-index: 20;
  308. position: relative;
  309. overflow: hidden;
  310. .dot {
  311. position: absolute;
  312. bottom: 20rpx;
  313. left: 0;
  314. width: 100%;
  315. padding: 0 20rpx;
  316. .dot-item {
  317. width: 12rpx;
  318. height: 12rpx;
  319. border-radius: 6rpx;
  320. margin-right: 16rpx;
  321. background: #dddddd;
  322. &:last-child {
  323. margin-right: 0;
  324. }
  325. &.active {
  326. background: var(--view-theme);
  327. }
  328. }
  329. .small {
  330. .dot-item {
  331. width: 10rpx;
  332. height: 10rpx;
  333. border-radius: 5rpx;
  334. margin-right: 8rpx;
  335. &.active {
  336. width: 18rpx;
  337. }
  338. }
  339. }
  340. .line {
  341. .dot-item {
  342. width: 20rpx;
  343. height: 6rpx;
  344. border-radius: 3rpx;
  345. margin-right: 10rpx;
  346. }
  347. }
  348. .progress {
  349. width: 60rpx;
  350. height: 6rpx;
  351. border-radius: 3rpx;
  352. background: #dddddd;
  353. .inner {
  354. width: 33%;
  355. height: 6rpx;
  356. border-radius: 3rpx;
  357. background: var(--view-theme);
  358. transition: 0.3s;
  359. }
  360. }
  361. }
  362. .swiper-item {
  363. width: 100%;
  364. height: 100%;
  365. transform: scale(0.9);
  366. transition: 0.3s;
  367. // &.active {
  368. // transform: scale(1);
  369. // }
  370. }
  371. .image {
  372. width: 100%;
  373. height: 100%;
  374. }
  375. // 圆形指示点
  376. &.circular {
  377. ::v-deep.uni-swiper-dot {
  378. width: 10rpx !important;
  379. height: 10rpx !important;
  380. background: rgba(0, 0, 0, 0.4) !important;
  381. }
  382. ::v-deep.uni-swiper-dot-active {
  383. background: #fff !important;
  384. }
  385. }
  386. // 方形指示点
  387. &.square {
  388. ::v-deep.uni-swiper-dot {
  389. width: 20rpx !important;
  390. height: 5rpx !important;
  391. border-radius: 3rpx;
  392. background: rgba(0, 0, 0, 0.4) !important;
  393. }
  394. ::v-deep.uni-swiper-dot-active {
  395. background: #fff !important;
  396. }
  397. }
  398. }
  399. }
  400. </style>