coursePopup.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. let popupViewData = null
  2. export function coursePopup(options = {},callBack) {
  3. // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心
  4. const screenWidth = plus.screen.resolutionWidth;
  5. const screenHeight = plus.screen.resolutionHeight;
  6. //弹窗容器宽度
  7. const popupViewWidth = screenWidth * 0.8;
  8. // 弹窗容器的Padding
  9. const viewContentPadding = 12;
  10. // 弹窗容器的宽度
  11. const viewContentWidth = popupViewWidth - (viewContentPadding * 2);
  12. let iconWid=popupViewWidth/4.0;
  13. let icWidth=35;
  14. let imgWidth = viewContentWidth
  15. let imgHeight = viewContentWidth / 1.78
  16. // 弹窗容器高度
  17. let popupViewHeight = viewContentPadding * 2 + imgHeight + icWidth + 140;
  18. let elementList = [
  19. {
  20. tag: 'rect', //背景色
  21. color: '#fff',
  22. rectStyles:{
  23. radius: "8px"
  24. }
  25. },
  26. // 头像
  27. {
  28. src:'./static/images/ad/zsfw_icon40.png',
  29. id: "headimg",
  30. tag: "img",
  31. position: {
  32. top: viewContentPadding + 'px',
  33. left: viewContentPadding + "px",
  34. width: icWidth+"px",
  35. height: icWidth +"px",
  36. }
  37. },
  38. // 名称
  39. {
  40. tag: 'font',
  41. id: 'name',
  42. text: "标题标题标题标题标题标题标题标题标题标题标题标题",
  43. textStyles: {
  44. size: '14px',
  45. color: "#222",
  46. verticalAlign: "middle",
  47. whiteSpace: "normal",
  48. overflow: "ellipsis",
  49. align: 'left'
  50. },
  51. position: {
  52. top: '5px',
  53. left: icWidth + 24 + "px",
  54. height: "34px",
  55. width: imgWidth - icWidth - 36 + 'px',
  56. }
  57. },
  58. // 描述
  59. {
  60. tag: 'font',
  61. id: 'text1',
  62. text: "给你分享了一个课程",
  63. textStyles: {
  64. size: '13px',
  65. color: "#999",
  66. verticalAlign: "middle",
  67. whiteSpace: "normal",
  68. overflow: "ellipsis",
  69. align: 'left'
  70. },
  71. position: {
  72. top: viewContentPadding + 10 + 'px',
  73. left: icWidth + 24 + "px",
  74. height: "34px",
  75. width: imgWidth - icWidth - 36 + 'px',
  76. }
  77. },
  78. {
  79. src:'https://cos.his.cdwjyyh.com/fs/20241122/0d29517f595e428989017b49e28ea437.jpg',
  80. id: "logo",
  81. tag: "img",
  82. position: {
  83. top: viewContentPadding*2 + icWidth + 'px',
  84. left: viewContentPadding+ 'px',
  85. width: imgWidth + 'px',
  86. height: imgHeight + 'px',
  87. },
  88. },
  89. // 标题
  90. {
  91. tag: 'font',
  92. id: 'title',
  93. text: "标题标题标题标题标题标题标题标题标题标题标题标题",
  94. textStyles: {
  95. size: '16px',
  96. color: "#222",
  97. verticalAlign: "middle",
  98. whiteSpace: "normal",
  99. overflow: "ellipsis",
  100. align: 'left'
  101. },
  102. position: {
  103. top: imgHeight + icWidth + viewContentPadding*2 + 'px',
  104. left: "10px",
  105. right: "10px",
  106. height: "36px",
  107. width: imgWidth + 'px',
  108. }
  109. },
  110. // 描述
  111. {
  112. tag: 'font',
  113. id: 'desc',
  114. text: "描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述描述",
  115. textStyles: {
  116. size: '13px',
  117. color: "#999",
  118. verticalAlign: "middle",
  119. whiteSpace: "normal",
  120. overflow: "ellipsis",
  121. align: 'left'
  122. },
  123. position: {
  124. top: imgHeight + icWidth + viewContentPadding*2 + 26 + 'px',
  125. left: "10px",
  126. right: "10px",
  127. height: "50px",
  128. width: imgWidth + 'px',
  129. }
  130. },
  131. ];
  132. let detailbtnEle = [{
  133. tag: 'rect', //背景色
  134. id: 'button',
  135. color: '#FF5C03',
  136. rectStyles:{
  137. radius: "22px",
  138. },
  139. position:{
  140. left:"10%",
  141. top: 0,
  142. width:"80%",
  143. height:"44px",
  144. }
  145. },{
  146. tag: 'font',
  147. id: 'buttontxt',
  148. text: "查看详情",
  149. textStyles: {
  150. size: '16px',
  151. color: "#fff",
  152. verticalAlign: "middle",
  153. whiteSpace: "normal",
  154. overflow: "ellipsis",
  155. align: 'center'
  156. },
  157. position: {
  158. left:"10%",
  159. top: 0,
  160. width:"80%",
  161. height:"44px",
  162. }
  163. }]
  164. // 弹窗遮罩层
  165. let maskLayer = new plus.nativeObj.View("maskLayer", { //先创建遮罩层
  166. top: '0px',
  167. left: '0px',
  168. height: '100%',
  169. width: '100%',
  170. backgroundColor: 'rgba(0,0,0,0.5)',
  171. visible: false
  172. });
  173. // 弹窗内容
  174. let popupView = new plus.nativeObj.View("popupView", { //创建底部图标菜单
  175. tag: "rect",
  176. top: (screenHeight - popupViewHeight - 70) / 2.0 + "px",
  177. left: '10%',
  178. height: popupViewHeight,
  179. width: "80%",
  180. });
  181. // 弹窗查看详情按钮
  182. let detailBtn = new plus.nativeObj.View("detailBtn", {
  183. tag: "rect",
  184. top: (screenHeight - popupViewHeight - 70) / 2.0 + imgHeight + icWidth + viewContentPadding*2 + 80 + 'px',
  185. left: "10%",
  186. width:"80%",
  187. height:"44px",
  188. });
  189. // 弹窗关闭按钮
  190. let closeBtnData = closeBtnDrawing();
  191. let closeWid=40;
  192. let closeBtn = new plus.nativeObj.View("closeBtn", {
  193. tag: "rect",
  194. top: (screenHeight - (popupViewHeight+closeWid+30))*0.5 +(popupViewHeight+30) + "px",
  195. left: ((closeBtnData.screenWidth - closeWid) / 2) +"px",
  196. height: closeWid+"px",
  197. width: closeWid+"px",
  198. });
  199. popupView.draw(elementList);
  200. detailBtn.draw(detailbtnEle)
  201. closeBtn.draw(closeBtnData.elementList);
  202. maskLayer.show();
  203. popupView.show();
  204. detailBtn.show();
  205. closeBtn.show();
  206. detailBtn.addEventListener('click', (e) => {
  207. maskLayer.hide();
  208. popupView.hide();
  209. detailBtn.hide();
  210. closeBtn.hide();
  211. callBack(1);
  212. });
  213. closeBtn.addEventListener("click", function(e) {
  214. maskLayer.hide();
  215. popupView.hide();
  216. detailBtn.hide();
  217. closeBtn.hide();
  218. });
  219. }
  220. //关闭按钮绘图
  221. function closeBtnDrawing(){
  222. // 以下为计算菜单的nview绘制布局,为固定算法,使用者无关关心
  223. const screenWidth = plus.screen.resolutionWidth;
  224. const screenHeight = plus.screen.resolutionHeight;
  225. //弹窗容器宽度
  226. const popupViewWidth = screenWidth * 0.8;
  227. // 弹窗容器的Padding
  228. const viewContentPadding = 12;
  229. // 弹窗容器的宽度
  230. const viewContentWidth = popupViewWidth - (viewContentPadding * 2);
  231. // 弹窗容器高度
  232. let closeY = viewContentPadding * 7 + 60+32;
  233. let elementList = [
  234. {
  235. tag: 'rect', //背景色
  236. color: 'rgba(255,255,255,0)',
  237. rectStyles:{
  238. radius: "0px"
  239. }
  240. },
  241. {
  242. src:'./static/images/ad/close_icon.png',
  243. id: "close",
  244. tag: "img",
  245. position: {
  246. top: '0px',
  247. left: "0px",
  248. width: "32px",
  249. height: "32px",
  250. }
  251. }
  252. ];
  253. return {
  254. popupViewHeight:32,
  255. popupViewWidth:popupViewWidth,
  256. screenWidth:screenWidth,
  257. screenHeight:screenHeight,
  258. elementList: elementList
  259. };
  260. }