u-announcement.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="u-announcement">
  3. <view class="u-notice-bar" :style="{backgroundColor: bgColor}" @click="take(true)">
  4. <view class="u-direction-row">
  5. <view class="u-icon-wrap">
  6. <image class="u-icon-left" :src="icon ? icon : '../../../static/image/icon/icon-notice.png'"></image>
  7. <text class="u-text" :style="{color: textColor}">{{name}}</text>
  8. </view>
  9. <view class="u-notice-box" id="u-notice-box">
  10. <view
  11. class="u-notice-content"
  12. id="u-notice-content"
  13. :style="{
  14. animationDuration: animationDuration,
  15. animationPlayState: animationPlayState
  16. }"
  17. >
  18. <text class="u-notice-text u-text" :style="{color: textColor}">{{showText}}</text>
  19. </view>
  20. </view>
  21. <view class="u-icon-wrap">
  22. <image class="u-icon-right" src="../../../static/image/icon/arrow-right-white.png" ></image>
  23. </view>
  24. </view>
  25. </view>
  26. <u-popup :length="600" mode="center" v-model="visibleSync" :zoom="false">
  27. <view class="app-top-image" :style="{backgroundImage: `url(${headerUrl})`}" v-if="headerUrl"></view>
  28. <!-- <view class="app-top-image" style="background-image: url(https://qiantengteng.9026.com/web/statics/img/mall/notice.jpg);"></view> -->
  29. <!-- <view class="app-top-image icon" v-else></view> -->
  30. <view class="u-bottom-content">
  31. <scroll-view scroll-y class="u-content">
  32. {{content}}
  33. </scroll-view>
  34. <view class="u-button" hover-class="u-hover-class" :style="btnStyle" @click="take(false)">
  35. {{btnText}}
  36. </view>
  37. </view>
  38. </u-popup>
  39. </view>
  40. </template>
  41. <script>
  42. import uPopup from '../../../components/basic-component/u-popup/u-popup.vue';
  43. export default {
  44. data() {
  45. return {
  46. animationDuration: '10s',
  47. animationPlayState: 'paused',
  48. showText: '',
  49. visibleSync: false,
  50. showDrawer: false,
  51. timer: null
  52. }
  53. },
  54. components: {
  55. uPopup
  56. },
  57. props: {
  58. content: String,
  59. bgColor: {
  60. type: String,
  61. default: '#f67f79'
  62. },
  63. icon: {
  64. type: String,
  65. default: ''
  66. },
  67. name: {
  68. type: String,
  69. default: '公告'
  70. },
  71. textColor: {
  72. type: String,
  73. default: '#ffffff'
  74. },
  75. headerUrl: {
  76. type: String,
  77. default: ''
  78. },
  79. btnText: {
  80. type: String,
  81. default: '我知道了'
  82. },
  83. btnTextColor: {
  84. type: String,
  85. default: '#ffffff'
  86. },
  87. btnColor: {
  88. type: String,
  89. default: '#F84469'
  90. },
  91. btnRadius: {
  92. type: String,
  93. default: '40rpx'
  94. },
  95. btnWidth: {
  96. type: Number,
  97. default: 500
  98. }
  99. },
  100. watch: {
  101. content: {
  102. immediate: true,
  103. handler(newVal) {
  104. this.showText = newVal.replace(/[\r\n]/g,"");
  105. this.$nextTick(() => {
  106. this.initSize();
  107. });
  108. }
  109. }
  110. },
  111. methods: {
  112. initSize() {
  113. let query = [];
  114. let textQuery = new Promise(resolve => {
  115. uni.createSelectorQuery().in(this).select(`#u-notice-content`).boundingClientRect().exec(ret => {
  116. this.textWidth = ret[0].width;
  117. resolve();
  118. });
  119. });
  120. query.push(textQuery);
  121. Promise.all(query).then(() => {
  122. this.animationDuration = `${this.textWidth / uni.upx2px(100)}s`;
  123. this.animationPlayState = 'paused';
  124. setTimeout(() => {
  125. this.animationPlayState = 'running';
  126. }, 10);
  127. });
  128. },
  129. take(data) {
  130. this.visibleSync = data;
  131. }
  132. },
  133. computed: {
  134. btnStyle: function() {
  135. return `width: ${this.btnWidth}rpx;color:${this.btnTextColor};background-color:${this.btnColor};border-radius: ${this.btnRadius};`
  136. }
  137. },
  138. mounted() {
  139. this.$nextTick(() => {
  140. this.initSize();
  141. });
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .u-notice-bar {
  147. padding: 18upx 24upx;
  148. overflow: hidden;
  149. }
  150. .u-direction-row {
  151. display: flex;
  152. flex-direction: row;
  153. align-items: center;
  154. justify-content: space-between;
  155. }
  156. .u-icon-wrap {
  157. display: flex;
  158. align-items: center;
  159. }
  160. .u-icon-left {
  161. width: 36upx;
  162. height: 36upx;
  163. margin-right: 20upx;
  164. }
  165. .u-notice-box {
  166. flex: 1;
  167. display: flex;
  168. flex-direction: row;
  169. overflow: hidden;
  170. margin-left: 12upx;
  171. }
  172. .u-notice-text {
  173. font-size: 26upx;
  174. word-break: keep-all;
  175. white-space: nowrap
  176. }
  177. .u-notice-content {
  178. animation: u-loop-animation 10s linear infinite both;
  179. text-align: right;
  180. padding-left: 100%;
  181. display: flex;
  182. flex-direction: row;
  183. flex-wrap: nowrap;
  184. }
  185. @keyframes u-loop-animation {
  186. 0% {
  187. transform: translate3d(0, 0, 0);
  188. }
  189. 100% {
  190. transform: translate3d(-100%, 0, 0);
  191. }
  192. }
  193. .u-icon-right {
  194. width: 12upx;
  195. height: 22upx;
  196. margin-left: 10upx;
  197. }
  198. .u-text {
  199. font-size: 26upx;
  200. }
  201. .app-transparent-frame {
  202. width: 600upx;
  203. }
  204. .app-top-image {
  205. height: #{150rpx};
  206. width: #{600rpx};
  207. background-repeat: no-repeat;
  208. background-size: cover;
  209. &.icon {
  210. background-image: url("../../../static/image/icon/announcement.png");
  211. }
  212. }
  213. .u-bottom-content {
  214. background-color: #ffffff;
  215. padding: 50upx;
  216. border-bottom-right-radius: 11upx;
  217. border-bottom-left-radius: 11upx;
  218. }
  219. .u-button {
  220. margin: 0 auto;
  221. font-size: 31upx;
  222. text-align: center;
  223. height: 80upx;
  224. line-height: 80upx;
  225. }
  226. .u-content {
  227. display: block;
  228. min-height: 144upx;
  229. max-height: 285upx;
  230. width: 500upx;
  231. margin-bottom: 66upx;
  232. word-break: break-all;
  233. line-height: 48upx;
  234. }
  235. </style>