index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view class="U000004-template1" :style="wrapper_style" :class="className">
  3. <!-- style -->
  4. <view v-html="css"></view>
  5. <!-- 列表 -->
  6. <template v-if="datas.preview_color">
  7. <view v-if="datas.show_title" class="morebox">
  8. <view :style="title_style" class="title">{{ title }}</view>
  9. <view class="title2" @click="more">查看更多
  10. <u-icon :style="img_style2" color="#949494" name="arrow-right" size="14"></u-icon>
  11. </view>
  12. </view>
  13. <view v-if="list.length <= 0" style="text-align: center;font-size: 16px;line-height: 32px">
  14. 请先添加监控
  15. </view>
  16. <view class="button-box" :style="box_button" v-if="list && list.length > 0">
  17. <view @click="govoide(item.id)" class="box_a" :style="boxa_style" v-for="(item, index) in list"
  18. :key="item.id">
  19. <image class="button-img" :style="imag_style" :src="item.pic || emptyImage" alt=""></image>
  20. <image :src="settingFile.root_img+'/static/app/imgs/much/play.png'" class="item-play" mode="">
  21. </image>
  22. <text class="button-title" :style="titlea_style">{{ item.title }}</text>
  23. </view>
  24. </view>
  25. </template>
  26. </view>
  27. </template>
  28. <script>
  29. // 自定义样式
  30. const css = function() {
  31. if (this.datas.preview_color) {
  32. const {
  33. padding_top,
  34. padding_bottom,
  35. padding_left,
  36. padding_right,
  37. logo_image_size,
  38. border_radius,
  39. button_number,
  40. preview_color,
  41. font_size,
  42. font_color,
  43. } = this.datas;
  44. return `
  45. .component-${this.id} .button-box{
  46. padding:0;
  47. background-image: url(${preview_color.isColor == 2 ? preview_color.image : ''});
  48. background-size: 100% 100%;
  49. background-position: center;
  50. background-repeat: no-repeat;
  51. }
  52. .component-${this.id} .button-box .box_a {
  53. width: ${button_number == 2 ? '50' : '33.3'}%;
  54. }
  55. .component-${this.id} .button-img{
  56. width: ${logo_image_size}px;
  57. height: ${logo_image_size}px;
  58. border-radius: ${border_radius}px;
  59. }
  60. .component-${this.id} .button-title{
  61. font-size:${font_size}px;
  62. color: ${font_color};
  63. }
  64. `;
  65. }
  66. };
  67. import landApi from '@/api/land/index.js'
  68. export default {
  69. props: ['datas', 'styles', 'languages'],
  70. data() {
  71. let siteinfo = getApp().globalData.siteinfo;
  72. this.initdata();
  73. return {
  74. settingFile: siteinfo,
  75. emptyImage: siteinfo.root_img + '/static/app/image.png',
  76. scroll_list: [], //轮播时用的数值结构
  77. // 轮播图设置
  78. swiperOption: {
  79. autoplay: false,
  80. // loop: true, loop模式第二轮循环的时候第一张会闪烁
  81. delay: 3000,
  82. observer: true,
  83. // autoHeight: true,
  84. pagination: {
  85. el: '.swiper-pagination',
  86. }
  87. },
  88. list: []
  89. };
  90. },
  91. computed: {
  92. titlea_style() {
  93. if (this.datas.preview_color) {
  94. const {
  95. font_size,
  96. font_color
  97. } = this.datas;
  98. return `
  99. font-size:${font_size}px;
  100. color: ${font_color};
  101. `;
  102. }
  103. },
  104. imag_style() {
  105. if (this.datas.preview_color) {
  106. const {
  107. logo_image_size,
  108. border_radius
  109. } = this.datas;
  110. let ht = parseInt(logo_image_size * 2 / 3)
  111. return `
  112. width: ${logo_image_size*2}rpx;
  113. height: ${ht*2}rpx;
  114. border-radius: ${border_radius*2}rpx;
  115. `;
  116. }
  117. },
  118. boxa_style() {
  119. if (this.datas.preview_color) {
  120. const {
  121. button_number,
  122. } = this.datas;
  123. return `
  124. width: ${button_number == 2 ? '50' : '33.3'}%;
  125. `;
  126. }
  127. },
  128. box_button() {
  129. if (this.datas.preview_color) {
  130. const {
  131. preview_color,
  132. bg_color
  133. } = this.datas;
  134. return `
  135. background-color: ${bg_color};
  136. padding:0;
  137. background-image: url(${preview_color.isColor == 2 ? preview_color.image : ''});
  138. background-size: 100% 100%;
  139. background-position: center;
  140. background-repeat: no-repeat;
  141. `;
  142. }
  143. },
  144. // 副标题栏样式
  145. title_style() {
  146. const {
  147. text_size,
  148. text_color,
  149. } = this.datas;
  150. return `
  151. font-size: ${text_size}px;
  152. color: ${text_color};
  153. `;
  154. },
  155. img_style2() {
  156. const {
  157. button_size
  158. } = this.datas
  159. return `
  160. width:${button_size}px;
  161. height:${button_size}px;
  162. margin:auto;
  163. `;
  164. },
  165. /** 样式 */
  166. wrapper_style() {
  167. const {
  168. padding_top,
  169. padding_bottom,
  170. padding_left,
  171. padding_right,
  172. bg_color
  173. } = this.datas;
  174. return `
  175. background-color:${bg_color};
  176. padding: ${padding_top}px ${padding_right}px ${padding_bottom}px ${padding_left}px;
  177. background-size: 100% auto;
  178. bakcground-position: center;
  179. `;
  180. },
  181. css() {
  182. return '<style>' + css.call(this) + '</style>';
  183. },
  184. className() {
  185. const name = ['component-wrapper', `component-${this.id}`];
  186. return name;
  187. },
  188. button_number() {
  189. return this.datas.button_number;
  190. },
  191. button_line() {
  192. return this.datas.button_line || 1;
  193. },
  194. img_style() {
  195. const {
  196. button_size
  197. } = this.datas
  198. return `
  199. width:${button_size}px;
  200. height:${button_size}px;
  201. margin:auto;
  202. `;
  203. },
  204. /** 标题内容 */
  205. title() {
  206. return this.datas.title || '标题';
  207. },
  208. },
  209. watch: {
  210. button_number(newValue) {
  211. let list = this.datas.list;
  212. this.scroll_list = [];
  213. if (!this.datas.button_line) {
  214. this.datas.button_line = 1
  215. }
  216. let page = Math.ceil(this.datas.list.length / newValue / this.datas.button_line); //==> 页数
  217. let num = newValue * this.datas.button_line; // ==> 每页多少个
  218. for (let i = 0; i < page; i++) {
  219. this.scroll_list.push(list.slice(i * num, (i + 1) * num))
  220. }
  221. },
  222. button_line(newValue) {
  223. let list = this.datas.list;
  224. this.scroll_list = [];
  225. if (!newValue) {
  226. newValue = 1
  227. }
  228. let page = Math.ceil(this.datas.list.length / this.datas.button_number / newValue); //==> 页数
  229. let num = this.datas.button_number * newValue; // ==> 每页多少个
  230. for (let i = 0; i < page; i++) {
  231. this.scroll_list.push(list.slice(i * num, (i + 1) * num))
  232. }
  233. }
  234. },
  235. methods: {
  236. more() {
  237. uni.navigateTo({
  238. url: '/pagesE/pages/broadcast/broadcast'
  239. })
  240. },
  241. govoide(id) {
  242. uni.navigateTo({
  243. url: '/pagesE/pages/broadcast/transmit?id=' + id
  244. })
  245. },
  246. initdata() {
  247. let that = this
  248. let ids = []
  249. that.datas.goods.forEach(ele => {
  250. ids.push(ele.id)
  251. })
  252. let res = landApi.getlist({
  253. gids: ids,
  254. gtype: 'monitor',
  255. }).then(res => {
  256. if (res.status == 200) {
  257. that.list = res.data;
  258. }
  259. });
  260. },
  261. initButtons() {
  262. if (this.datas.list) {
  263. let list = this.datas.list;
  264. this.scroll_list = [];
  265. if (!this.datas.button_line) {
  266. this.datas.button_line = 1
  267. }
  268. let page = Math.ceil(this.datas.list.length / this.datas.button_number / this.datas
  269. .button_line); //==> 页数
  270. let num = this.datas.button_number * this.datas.button_line; // ==> 每页多少个
  271. for (let i = 0; i < page; i++) {
  272. this.scroll_list.push(list.slice(i * num, (i + 1) * num))
  273. }
  274. }
  275. }
  276. },
  277. mounted() {
  278. this.$nextTick(() => {
  279. this.initButtons();
  280. })
  281. }
  282. };
  283. </script>
  284. <style lang="less" scoped>
  285. // 默认
  286. .component-wrapper {
  287. .morebox {
  288. display: flex;
  289. justify-content: space-between;
  290. align-items: center;
  291. padding: 0 12px;
  292. margin-bottom: 5px;
  293. .title2 {
  294. display: flex;
  295. font-size: 28rpx;
  296. color: #949494;
  297. align-items: center;
  298. }
  299. }
  300. .box_a {
  301. .item-play {
  302. width: 55rpx;
  303. height: 55rpx;
  304. position: absolute;
  305. top: 45%;
  306. left: 50%;
  307. margin-top: -27.5rpx;
  308. margin-left: -27.5rpx;
  309. }
  310. }
  311. .button-box {
  312. display: flex;
  313. flex-wrap: wrap;
  314. width: 100%;
  315. view {
  316. /*flex: 1;*/
  317. /*width: 25%;*/
  318. position: relative;
  319. margin: 10px 0;
  320. list-style: none;
  321. display: flex;
  322. flex-direction: column;
  323. align-self: center;
  324. justify-self: center;
  325. }
  326. .button-img {
  327. margin: 0 auto;
  328. margin-bottom: 5px;
  329. }
  330. .button-title {
  331. text-align: center;
  332. margin: 4rpx;
  333. text-overflow: ellipsis;
  334. white-space: nowrap;
  335. word-wrap: break-word;
  336. overflow: hidden;
  337. }
  338. }
  339. }
  340. </style>