pictureCube.vue 7.7 KB

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