pictureCube.vue 7.7 KB

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