index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <view :style="warpCss">
  3. <view :style="maskLayer"></view>
  4. <view class="diy-active-cube relative">
  5. <view class="active-cube-wrap pt-[28rpx] px-[20rpx] pb-[24rpx]">
  6. <view class="flex items-center" v-if="diyComponent.titleStyle.value == 'style-1'">
  7. <view class="mr-[10rpx] font-500 text-[30rpx]" :style="{color: diyComponent.titleColor }" @click="diyStore.toRedirect(diyComponent.textLink)">{{ diyComponent.text }}</view>
  8. <view v-if="diyComponent.subTitle.text" @click="diyStore.toRedirect(diyComponent.subTitle.link)"
  9. class="text-center text-[22rpx] rounded-[40rpx] rounded-tl-[10rpx] py-[6rpx] px-[14rpx]"
  10. :style="{'color': diyComponent.subTitle.textColor, background: 'linear-gradient(90deg, '+ diyComponent.subTitle.startColor + ', '+ diyComponent.subTitle.endColor + ')'}">{{ diyComponent.subTitle.text }}</view>
  11. </view>
  12. <view class="flex items-center" v-if="diyComponent.titleStyle.value == 'style-2'">
  13. <view class="mr-[10rpx] font-500 text-[30rpx]" :style="{color: diyComponent.titleColor }" @click="diyStore.toRedirect(diyComponent.textLink)">{{ diyComponent.text }}</view>
  14. <view v-if="diyComponent.subTitle.text" @click="diyStore.toRedirect(diyComponent.subTitle.link)"
  15. class="text-center text-[22rpx] rounded-[6rpx] py-[6rpx] px-[14rpx]"
  16. :style="{'color': diyComponent.subTitle.textColor, background: 'linear-gradient(90deg, '+ diyComponent.subTitle.startColor + ', '+ diyComponent.subTitle.endColor + ')'}">{{ diyComponent.subTitle.text }}</view>
  17. </view>
  18. <view class="flex items-center" v-if="diyComponent.titleStyle.value == 'style-3'">
  19. <view class="mr-[10rpx] font-500 text-[30rpx]" @click="diyStore.toRedirect(diyComponent.textLink)" :style="{color: diyComponent.titleColor }">{{ diyComponent.text }}</view>
  20. <view class="relative h-[36rpx]" @click="diyStore.toRedirect(diyComponent.subTitle.link)">
  21. <view v-if="diyComponent.subTitle.text"
  22. class="flex items-center text-[22rpx] leading-0 min-w-[60rpx] h-[34rpx] pl-[10rpx] pr-[34rpx]"
  23. :style="{'color': diyComponent.subTitle.textColor, 'background-image':'url('+img('https://v6.site.niucloud.com/static/resource/images/diy/active_cube/bg_2.png')+')','background-size': '100% 100%','background-repeat': 'no-repeat'}">{{ diyComponent.subTitle.text }}</view>
  24. <!-- <image class="absolute left-0 top-0 bottom-0 !w-[16rpx] !h-[36rpx]" :src="img('static/resource/images/diy/active_cube/block_style2_1.png')" mode="scaleToFill"/>
  25. <image class="absolute right-0 top-0 bottom-0 !w-[28rpx] !h-[36rpx]" :src="img('static/resource/images/diy/active_cube/block_style2_2.png')" mode="scaleToFill"/> -->
  26. </view>
  27. </view>
  28. <view class="flex items-center justify-between" v-if="diyComponent.titleStyle.value == 'style-4'">
  29. <view class="font-500 text-[30rpx]" @click="diyStore.toRedirect(diyComponent.textLink)" :style="{color: diyComponent.titleColor }">{{ diyComponent.text }}</view>
  30. <view v-if="diyComponent.subTitle.text" @click="diyStore.toRedirect(diyComponent.subTitle.link)" class="text-[22rpx] rounded-[40rpx] pl-[16rpx] pr-[8rpx] h-[42rpx] flex-center" :style="{'color': diyComponent.subTitle.textColor, background: 'linear-gradient(90deg, '+ diyComponent.subTitle.startColor + ', '+ diyComponent.subTitle.endColor + ')'}">
  31. <text>{{ diyComponent.subTitle.text }}</text>
  32. <text class="nc-iconfont nc-icon-youV6xx !text-[26rpx]"></text>
  33. </view>
  34. </view>
  35. <view class="flex items-center" v-if="diyComponent.titleStyle.value == 'style-5'">
  36. <view class="h-[32rpx] flex items-center" v-if="diyComponent.textImg" @click="diyStore.toRedirect(diyComponent.textLink)">
  37. <image class="h-[100%] w-[auto]" :src="img(diyComponent.textImg)" mode="heightFix" />
  38. </view>
  39. <view v-if="diyComponent.subTitle.text && diyComponent.textImg" class="mx-[16rpx] w-[2rpx] h-[24rpx]" :style="{'background': diyComponent.subTitle.textColor}"></view>
  40. <view v-if="diyComponent.subTitle.text" @click="diyStore.toRedirect(diyComponent.subTitle.link)" class="text-center text-[22rpx] py-[6rpx]"
  41. :style="{'color': diyComponent.subTitle.textColor, background: 'linear-gradient(90deg, '+ diyComponent.subTitle.startColor + ', '+ diyComponent.subTitle.endColor + ')'}">{{ diyComponent.subTitle.text }}</view>
  42. </view>
  43. <view class="bd flex flex-wrap justify-between">
  44. <template v-for="item in diyComponent.list" :key="item.id">
  45. <view v-if="diyComponent.blockStyle.value == 'style-1'" @click="diyStore.toRedirect(item.link)" class="item flex justify-between px-[20rpx] py-[30rpx] bg-white mt-[20rpx]" :style="commonTempCss(item)">
  46. <view class="flex-1 flex items-baseline flex-col">
  47. <view class="text-[28rpx] pb-[10rpx] text-[#333]" :style="{ fontWeight : diyComponent.blockStyle.fontWeight }">{{ item.title.text }}</view>
  48. <view class="text-[22rpx] text-[#999] pb-[30rpx]">{{ item.subTitle.text }}</view>
  49. <view class="link relative text-[22rpx] leading-[40rpx] flex items-center text-white rounded-r-[20rpx] h-[40rpx] pl-[26rpx] pr-[10rpx]"
  50. :style="btnCss(item.moreTitle)" v-if="item.moreTitle.text">
  51. <text class="mr-[8rpx]">{{ item.moreTitle.text }}</text>
  52. <text class="iconfont iconjiantou-you-cuxiantiao-fill !text-[20rpx] text-[#fff]"></text>
  53. <image class="absolute left-0 top-0 bottom-0 !w-[28rpx]" :src="img('https://v6.site.niucloud.com/static/resource/images/diy/active_cube/block_style1_1.png')" mode="scaleToFill" />
  54. </view>
  55. </view>
  56. <view class="img-box ml-[10rpx] w-[130rpx]" v-if="item.imageUrl">
  57. <image :src="img(item.imageUrl)" mode="aspectFit" />
  58. </view>
  59. <view class="img-box ml-[10rpx] flex items-center justify-center w-[130rpx] bg-[#f3f4f6]" v-else>
  60. <u-icon name="photo" color="#999" size="50"></u-icon>
  61. </view>
  62. </view>
  63. <view v-if="diyComponent.blockStyle.value == 'style-2'" @click="diyStore.toRedirect(item.link)" class="item h-[150rpx] flex justify-between p-[20rpx] bg-white mt-[20rpx]"
  64. :style="commonTempCss(item)">
  65. <view class="flex-1 flex items-baseline flex-col">
  66. <view class="text-[26rpx] mt-[10rpx] pb-[16rpx]" :style="{ fontWeight : diyComponent.blockStyle.fontWeight }">{{ item.title.text }}</view>
  67. <view class="text-[22rpx] text-gray-500 pb-[26rpx]">{{ item.subTitle.text }}</view>
  68. <view class="link relative text-[22rpx] leading-[40rpx] flex items-center text-white rounded-[20rpx] h-[40rpx] pl-[20rpx] pr-[10rpx]" :style="btnCss(item.moreTitle)" v-if="item.moreTitle.text">
  69. <text class="mr-[8rpx]" :class="{'italic': diyComponent.blockStyle.btnText == 'italics'}">{{ item.moreTitle.text }}</text>
  70. <text class="iconfont iconjiantou-you-cuxiantiao-fill !text-[20rpx] text-[#fff]"></text>
  71. </view>
  72. </view>
  73. <view class="img-box ml-[10rpx] w-[130rpx]" v-if="item.imageUrl">
  74. <image :src="img(item.imageUrl)" mode="aspectFit" />
  75. </view>
  76. <view class="img-box ml-[10rpx] flex items-center justify-center w-[130rpx] bg-[#f3f4f6]" v-else>
  77. <u-icon name="photo" color="#999" size="50"></u-icon>
  78. </view>
  79. </view>
  80. </template>
  81. </view>
  82. <scroll-view :scroll-x="true" class="whitespace-nowrap" :id="'warpStyle3-'+diyComponent.id" v-if="diyComponent.blockStyle.value == 'style-3'">
  83. <view v-for="(item,index) in diyComponent.list" :key="item.id" class="inline-flex">
  84. <view :id="'item'+index+diyComponent.id" @click="diyStore.toRedirect(item.link)"
  85. class="flex flex-col items-center justify-between p-[10rpx] bg-white mt-[20rpx] w-[157rpx] h-[200rpx] box-border"
  86. :style="itemStyle3 + commonTempCss(item)"
  87. :class="{'!mr-[0rpx]': index+1 === diyComponent.list.length}">
  88. <view class="w-[141rpx] h-[141rpx] rounded-[var(--rounded-small)] overflow-hidden" v-if="item.imageUrl">
  89. <image class="w-[141rpx] h-[141rpx]" :src="img(item.imageUrl)" mode="aspectFit" />
  90. </view>
  91. <view class="w-[141rpx] h-[141rpx] relative flex-shrink-0" v-else>
  92. <view class="absolute left-0 top-0 flex items-center justify-center w-[141rpx] h-[141rpx] bg-[#f3f4f6]">
  93. <u-icon name="photo" color="#999" size="50"></u-icon>
  94. </view>
  95. </view>
  96. <view class="mt-[10rpx] mb-[2rpx] text-[26rpx]" :style="{ color : item.title.textColor,fontWeight : diyComponent.blockStyle.fontWeight }">{{ item.title.text }}</view>
  97. </view>
  98. </view>
  99. </scroll-view>
  100. <scroll-view scroll-x="true" class="whitespace-nowrap" :id="'warpStyle4-'+diyComponent.id" v-if="diyComponent.blockStyle.value == 'style-4'">
  101. <view v-for="(item,index) in diyComponent.list" :key="item.id" class="inline-flex">
  102. <view :id="'item'+index+diyComponent.id" @click="diyStore.toRedirect(item.link)"
  103. class="flex flex-col items-center justify-between p-[4rpx] bg-[#F93D02] mt-[20rpx] box-border"
  104. :class="{'!mr-[0rpx]': index+1 === diyComponent.list.length}"
  105. :style="commonTempCss(item) + itemStyle4">
  106. <view class="w-[149rpx] h-[149rpx] box-border px-[18rpx] pt-[16rpx] pb-[6rpx] bg-[#fff] flex flex-col items-center rounded-[var(--rounded-small)]">
  107. <view class="w-[112rpx] h-[102rpx]" v-if="item.imageUrl"><image class="w-[112rpx] h-[102rpx]" :src="img(item.imageUrl)" mode="aspectFit" /></view>
  108. <view class="w-[112rpx] h-[102rpx] relative flex-shrink-0" v-else>
  109. <view class="absolute left-0 top-0 flex items-center justify-center w-[112rpx] h-[102rpx] bg-[#f3f4f6]">
  110. <u-icon name="photo" color="#999" size="50"></u-icon>
  111. </view>
  112. </view>
  113. <view class="relative -mt-[10rpx] text-[20rpx] bg-[#F3DAC5] text-[#ED6E00] rounded-[16rpx] px-[12rpx] h-[34rpx] flex-center"
  114. :style="{ color : item.subTitle.textColor, background : 'linear-gradient(to right,'+ item.subTitle.startColor +','+ item.subTitle.endColor + ')' }">{{ item.subTitle.text }}</view>
  115. </view>
  116. <view class="mt-[12rpx] mb-[12rpx] text-[26rpx] text-[#fff]"
  117. :style="{ fontWeight : (diyComponent.blockStyle.fontWeight == 'bold' ? diyComponent.blockStyle.fontWeight : '500') }">{{ item.title.text }}</view>
  118. </view>
  119. </view>
  120. </scroll-view>
  121. </view>
  122. </view>
  123. </view>
  124. </template>
  125. <script setup lang="ts">
  126. // 活动魔方组件
  127. import { ref, computed, watch, onMounted, nextTick, getCurrentInstance } from 'vue';
  128. import useDiyStore from '@/app/stores/diy';
  129. import { img } from '@/utils/common';
  130. const props = defineProps(['component', 'index']);
  131. const diyStore = useDiyStore();
  132. const diyComponent = computed(() => {
  133. if (diyStore.mode == 'decorate') {
  134. return diyStore.value[props.index];
  135. } else {
  136. return props.component;
  137. }
  138. })
  139. const warpCss = computed(() => {
  140. let style = '';
  141. style += 'position:relative;';
  142. if (diyComponent.value.componentStartBgColor) {
  143. if (diyComponent.value.componentStartBgColor && diyComponent.value.componentEndBgColor) style += `background:linear-gradient(${ diyComponent.value.componentGradientAngle },${ diyComponent.value.componentStartBgColor },${ diyComponent.value.componentEndBgColor });`;
  144. else style += 'background-color:' + diyComponent.value.componentStartBgColor + ';';
  145. }
  146. if (diyComponent.value.componentBgUrl) {
  147. style += `background-image:url('${ img(diyComponent.value.componentBgUrl) }');`;
  148. style += 'background-size: cover;background-repeat: no-repeat;';
  149. }
  150. if (diyComponent.value.topRounded) style += 'border-top-left-radius:' + diyComponent.value.topRounded * 2 + 'rpx;';
  151. if (diyComponent.value.topRounded) style += 'border-top-right-radius:' + diyComponent.value.topRounded * 2 + 'rpx;';
  152. if (diyComponent.value.bottomRounded) style += 'border-bottom-left-radius:' + diyComponent.value.bottomRounded * 2 + 'rpx;';
  153. if (diyComponent.value.bottomRounded) style += 'border-bottom-right-radius:' + diyComponent.value.bottomRounded * 2 + 'rpx;';
  154. return style;
  155. })
  156. // 背景图加遮罩层
  157. const maskLayer = computed(() => {
  158. let style = '';
  159. if (diyComponent.value.componentBgUrl) {
  160. style += 'position:absolute;top:0;width:100%;';
  161. style += `background: rgba(0,0,0,${ diyComponent.value.componentBgAlpha / 10 });`;
  162. style += `height:${ height.value }px;`;
  163. if (diyComponent.value.topRounded) style += 'border-top-left-radius:' + diyComponent.value.topRounded * 2 + 'rpx;';
  164. if (diyComponent.value.topRounded) style += 'border-top-right-radius:' + diyComponent.value.topRounded * 2 + 'rpx;';
  165. if (diyComponent.value.bottomRounded) style += 'border-bottom-left-radius:' + diyComponent.value.bottomRounded * 2 + 'rpx;';
  166. if (diyComponent.value.bottomRounded) style += 'border-bottom-right-radius:' + diyComponent.value.bottomRounded * 2 + 'rpx;';
  167. }
  168. return style;
  169. });
  170. //商品样式三
  171. const itemStyle3 = ref('');
  172. const setItemStyle3 = () => {
  173. // #ifdef MP-WEIXIN
  174. uni.createSelectorQuery().in(instance).select('#warpStyle3-' + diyComponent.value.id).boundingClientRect((res: any) => {
  175. uni.createSelectorQuery().in(instance).select('#item0' + diyComponent.value.id).boundingClientRect((data: any) => {
  176. itemStyle3.value = `margin-right:${ (res.width - data.width * 4) / 3 }px;`
  177. }).exec()
  178. }).exec()
  179. // #endif
  180. // #ifdef H5
  181. itemStyle3.value = 'margin-right:14rpx;'
  182. // #endif
  183. };
  184. //商品样式四
  185. const itemStyle4 = ref('');
  186. const setItemStyle4 = () => {
  187. // #ifdef MP-WEIXIN
  188. uni.createSelectorQuery().in(instance).select('#warpStyle4-' + diyComponent.value.id).boundingClientRect((res: any) => {
  189. uni.createSelectorQuery().in(instance).select('#item0' + diyComponent.value.id).boundingClientRect((data: any) => {
  190. itemStyle4.value = `margin-right:${ (res.width - data.width * 4) / 3 }px;`
  191. }).exec()
  192. }).exec()
  193. // #endif
  194. // #ifdef H5
  195. itemStyle4.value = 'margin-right:14rpx;'
  196. // #endif
  197. };
  198. // 公共模块颜色
  199. const commonTempCss = (data: any) => {
  200. let style = '';
  201. if (data.listFrame.startColor && data.listFrame.endColor) {
  202. style += `background:linear-gradient(${ data.listFrame.startColor },${ data.listFrame.endColor });`;
  203. } else {
  204. style += `background:${ data.listFrame.startColor || data.listFrame.endColor };`;
  205. }
  206. if (diyComponent.value.topElementRounded) style += 'border-top-left-radius:' + diyComponent.value.topElementRounded * 2 + 'rpx;';
  207. if (diyComponent.value.topElementRounded) style += 'border-top-right-radius:' + diyComponent.value.topElementRounded * 2 + 'rpx;';
  208. if (diyComponent.value.bottomElementRounded) style += 'border-bottom-left-radius:' + diyComponent.value.bottomElementRounded * 2 + 'rpx;';
  209. if (diyComponent.value.bottomElementRounded) style += 'border-bottom-right-radius:' + diyComponent.value.bottomElementRounded * 2 + 'rpx;';
  210. style += 'overflow: hidden;';
  211. return style;
  212. }
  213. const btnCss = (item: any) => {
  214. let style = '';
  215. style += `background:linear-gradient(90deg,${ item.startColor },${ item.endColor });`;
  216. return style;
  217. };
  218. onMounted(() => {
  219. refresh();
  220. // 装修模式下刷新
  221. if (diyStore.mode == 'decorate') {
  222. watch(
  223. () => diyComponent.value,
  224. (newValue, oldValue) => {
  225. if (newValue && newValue.componentName == 'ActiveCube') {
  226. refresh();
  227. }
  228. }
  229. )
  230. } else {
  231. watch(
  232. () => diyComponent.value,
  233. (newValue, oldValue) => {
  234. refresh();
  235. }
  236. )
  237. }
  238. });
  239. const instance = getCurrentInstance();
  240. const height = ref(0)
  241. const refresh = () => {
  242. nextTick(() => {
  243. const query = uni.createSelectorQuery().in(instance);
  244. query.select('.diy-active-cube').boundingClientRect((data: any) => {
  245. height.value = data.height;
  246. }).exec();
  247. if (diyComponent.value.blockStyle.value == 'style-3') setItemStyle3()
  248. if (diyComponent.value.blockStyle.value == 'style-4') setItemStyle4()
  249. })
  250. }
  251. </script>
  252. <style lang="scss" scoped>
  253. .active-cube-wrap {
  254. .bd {
  255. .item {
  256. width: calc(46% - 20rpx);
  257. image {
  258. width: 100%;
  259. height: 100%;
  260. }
  261. }
  262. }
  263. }
  264. </style>