pictureCube.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <view class="pictureCube skeleton-rect" :class="{pageOn:bgStyle===1}"
  3. :style="{margin:'0 '+prConfig*2+'rpx',marginTop:slider*2+'rpx',background:bgColor}" v-if="picList.length"
  4. v-show="!isSortType">
  5. <view class="advertItem01" v-for="(item,index) in picList" :key="index" v-if="style==0" @click="goDetail(item)">
  6. <image :src="item.image" mode="widthFix"></image>
  7. </view>
  8. <view class="advertItem02 acea-row" v-if="style==1">
  9. <view class="item" v-for="(item,index) in picList" :key="index" @click="goDetail(item)">
  10. <image :src="item.image" mode="aspectFill" :style="'height:'+ imageH +'rpx;'"></image>
  11. </view>
  12. </view>
  13. <view class="advertItem02 advertItem03 acea-row" v-if="style==2">
  14. <view class="item" v-for="(item,index) in picList" :key="index" @click="goDetail(item)">
  15. <image :src="item.image" mode="aspectFill" :style="'height:'+ imageH +'rpx;'"></image>
  16. </view>
  17. </view>
  18. <view class="advertItem04 acea-row" v-if="style==3">
  19. <view class="item" @click="goDetail(picList[0])">
  20. <image :src="picList[0].image"></image>
  21. </view>
  22. <view class="item">
  23. <view class="pic" @click="goDetail(picList[1])">
  24. <image :src="picList[1].image"></image>
  25. </view>
  26. <view class="pic" @click="goDetail(picList[2])">
  27. <image :src="picList[2].image"></image>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="advertItem02 advertItem05 acea-row" v-if="style==4">
  32. <view class="item" v-for="(item,index) in picList" :key="index" @click="goDetail(item)">
  33. <image :src="item.image" mode="aspectFill" :style="'height:'+ imageH +'rpx;'"></image>
  34. </view>
  35. </view>
  36. <view class="advertItem02 advertItem06 acea-row" v-if="style==5">
  37. <view class="item" v-for="(item,index) in picList" :key="index" @click="goDetail(item)">
  38. <image :src="item.image" mode="aspectFill"></image>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. name: 'pictureCube',
  46. props: {
  47. dataConfig: {
  48. type: Object,
  49. default: () => {}
  50. },
  51. isSortType: {
  52. type: String | Number,
  53. default: 0
  54. }
  55. },
  56. data() {
  57. return {
  58. picList: this.dataConfig.picStyle.picList,
  59. style: this.dataConfig.tabConfig.tabVal,
  60. bgStyle: this.dataConfig.bgStyle.type,
  61. prConfig: this.dataConfig.prConfig.val,
  62. slider: this.dataConfig.mbConfig.val,
  63. bgColor: this.dataConfig.bgColor.color[0].item,
  64. widthC: '',
  65. imageH: ''
  66. };
  67. },
  68. mounted() {
  69. if (this.picList.length) {
  70. let that = this;
  71. this.$nextTick((e) => {
  72. if (this.style == 1) {
  73. this.widthC = 375
  74. } else if (this.style == 2) {
  75. this.widthC = 250
  76. } else if (this.style == 4) {
  77. this.widthC = 188
  78. }
  79. uni.getImageInfo({
  80. src: that.setDomain(that.picList[0].image),
  81. success: (res) => {
  82. if (res && res.height > 0) {
  83. let height = res.height * ((that.widthC - that.prConfig * 2) / res
  84. .width)
  85. that.$set(that, 'imageH', height);
  86. } else {
  87. that.$set(that, 'imageH', (that.widthC - that.prConfig * 2) * 2);
  88. }
  89. },
  90. fail: function(error) {
  91. that.$set(that, 'imageH', (that.widthC - that.prConfig * 2) * 2);
  92. }
  93. })
  94. })
  95. }
  96. },
  97. created() {},
  98. methods: {
  99. //替换安全域名
  100. setDomain: function(url) {
  101. url = url ? url.toString() : '';
  102. //本地调试打开,生产请注销
  103. if (url.indexOf("https://") > -1) return url;
  104. else return url.replace('http://', 'https://');
  105. },
  106. goDetail(url) {
  107. let urls = url.link
  108. if (urls.indexOf("http") != -1) {
  109. // #ifdef H5
  110. location.href = urls
  111. // #endif
  112. // #ifdef MP || APP-PLUS
  113. uni.navigateTo({
  114. url: `/pages/annex/web_view/index?url=${urls}`
  115. });
  116. // #endif
  117. } else {
  118. if (['/pages/goods_cate/goods_cate', '/pages/order_addcart/order_addcart', '/pages/user/index']
  119. .indexOf(urls) == -1) {
  120. uni.navigateTo({
  121. url: urls
  122. })
  123. } else {
  124. uni.reLaunch({
  125. url: urls
  126. })
  127. }
  128. }
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss">
  134. .pageOn {
  135. border-radius: 24rpx !important;
  136. .advertItem01 {
  137. image {
  138. border-radius: 20rpx;
  139. }
  140. }
  141. .advertItem02 {
  142. .item {
  143. &:nth-child(1) {
  144. image {
  145. border-radius: 20rpx 0 0 20rpx
  146. }
  147. }
  148. &:nth-child(2) {
  149. image {
  150. border-radius: 0 20rpx 20rpx 0
  151. }
  152. }
  153. }
  154. }
  155. .advertItem03 {
  156. .item {
  157. &:nth-child(1) {
  158. image {
  159. border-radius: 20rpx 0 0 20rpx
  160. }
  161. }
  162. &:nth-child(2) {
  163. image {
  164. border-radius: 0
  165. }
  166. }
  167. &:nth-child(3) {
  168. image {
  169. border-radius: 0 20rpx 20rpx 0
  170. }
  171. }
  172. }
  173. }
  174. .advertItem04 {
  175. .item {
  176. &:nth-child(1) {
  177. image {
  178. border-radius: 20rpx 0 0 20rpx
  179. }
  180. }
  181. &:nth-child(2) {
  182. .pic {
  183. &:nth-child(1) {
  184. image {
  185. border-radius: 0 20rpx 0 0
  186. }
  187. }
  188. &:nth-child(2) {
  189. image {
  190. border-radius: 0 0 20rpx 0
  191. }
  192. }
  193. }
  194. }
  195. }
  196. }
  197. .advertItem05 {
  198. .item {
  199. &:nth-child(1) {
  200. image {
  201. border-radius: 20rpx 0 0 20rpx
  202. }
  203. }
  204. &:nth-child(2) {
  205. image {
  206. border-radius: 0
  207. }
  208. }
  209. &:nth-child(4) {
  210. image {
  211. border-radius: 0 20rpx 20rpx 0
  212. }
  213. }
  214. }
  215. }
  216. .advertItem06 {
  217. .item {
  218. &:nth-child(1) {
  219. image {
  220. border-radius: 20rpx 0 0 0
  221. }
  222. }
  223. &:nth-child(2) {
  224. image {
  225. border-radius: 0 20rpx 0 0
  226. }
  227. }
  228. &:nth-child(3) {
  229. image {
  230. border-radius: 0 0 0 20rpx
  231. }
  232. }
  233. &:nth-child(4) {
  234. image {
  235. border-radius: 0 0 20rpx 0
  236. }
  237. }
  238. }
  239. }
  240. }
  241. .pictureCube {
  242. background-color: #fff;
  243. .advertItem01 {
  244. width: 100%;
  245. height: auto;
  246. image {
  247. width: 100%;
  248. height: 100%;
  249. display: block;
  250. }
  251. }
  252. .advertItem02 {
  253. // /deep/uni-image>img{
  254. // position: unset;
  255. // }
  256. width: 100%;
  257. .item {
  258. width: 50%;
  259. height: auto;
  260. image {
  261. width: 100%;
  262. height: 100%;
  263. display: block;
  264. }
  265. }
  266. }
  267. .advertItem03 {
  268. .item {
  269. width: 33.3333%;
  270. }
  271. }
  272. .advertItem04 {
  273. width: 100%;
  274. .item {
  275. width: 50%;
  276. height: 376rpx;
  277. .pic {
  278. width: 100%;
  279. height: 188rpx;
  280. }
  281. image {
  282. width: 100%;
  283. height: 100%;
  284. display: block;
  285. }
  286. }
  287. }
  288. .advertItem05 {
  289. .item {
  290. width: 25%;
  291. }
  292. }
  293. .advertItem06 {
  294. .item {
  295. width: 50%;
  296. height: 188rpx;
  297. }
  298. }
  299. }
  300. </style>