su-popup.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. "use strict";
  2. const sheep_index = require("../../index.js");
  3. const common_vendor = require("../../../common/vendor.js");
  4. require("../../url/index.js");
  5. require("../../store/index.js");
  6. require("../../store/app.js");
  7. require("../../api/promotion/diy.js");
  8. require("../../request/index.js");
  9. require("../../config/index.js");
  10. require("../../platform/index.js");
  11. require("../../platform/provider/wechat/index.js");
  12. require("../../platform/provider/wechat/miniProgram.js");
  13. require("../../api/member/auth.js");
  14. require("../../api/member/social.js");
  15. require("../../api/member/user.js");
  16. require("../../platform/provider/apple/index.js");
  17. require("../../platform/share.js");
  18. require("../../router/index.js");
  19. require("../../hooks/useModal.js");
  20. require("../../helper/index.js");
  21. require("../../helper/test.js");
  22. require("../../helper/digit.js");
  23. require("../../helper/throttle.js");
  24. require("../../platform/pay.js");
  25. require("../../api/pay/order.js");
  26. require("../../store/user.js");
  27. require("../../store/cart.js");
  28. require("../../api/trade/cart.js");
  29. require("../../api/pay/wallet.js");
  30. require("../../api/trade/order.js");
  31. require("../../api/promotion/coupon.js");
  32. require("../../store/sys.js");
  33. require("../../store/modal.js");
  34. require("../../config/zIndex.js");
  35. const __default__ = {
  36. name: "SuPopup",
  37. components: {},
  38. emits: ["change", "maskClick", "close"],
  39. props: {
  40. // 开启状态
  41. show: {
  42. type: Boolean,
  43. default: false
  44. },
  45. // 顶部,底部时有效
  46. space: {
  47. type: Number,
  48. default: 0
  49. },
  50. // 默认圆角
  51. round: {
  52. type: [String, Number],
  53. default: 0
  54. },
  55. // 是否显示关闭
  56. showClose: {
  57. type: Boolean,
  58. default: false
  59. },
  60. // 开启动画
  61. animation: {
  62. type: Boolean,
  63. default: true
  64. },
  65. // 弹出层类型,可选值,top: 顶部弹出层;bottom:底部弹出层;center:全屏弹出层
  66. // message: 消息提示 ; dialog : 对话框
  67. type: {
  68. type: String,
  69. default: "bottom"
  70. },
  71. // maskClick
  72. isMaskClick: {
  73. type: Boolean,
  74. default: null
  75. },
  76. // TODO 2 个版本后废弃属性 ,使用 isMaskClick
  77. maskClick: {
  78. type: Boolean,
  79. default: null
  80. },
  81. // 可设置none
  82. backgroundColor: {
  83. type: String,
  84. default: "#ffffff"
  85. },
  86. backgroundImage: {
  87. type: String,
  88. default: ""
  89. },
  90. safeArea: {
  91. type: Boolean,
  92. default: true
  93. },
  94. maskBackgroundColor: {
  95. type: String,
  96. default: "rgba(0, 0, 0, 0.4)"
  97. },
  98. zIndex: {
  99. type: [String, Number],
  100. default: 10075
  101. }
  102. },
  103. watch: {
  104. show: {
  105. handler: function(newValue, oldValue) {
  106. if (typeof oldValue === "undefined" && !newValue) {
  107. return;
  108. }
  109. if (newValue) {
  110. this.open();
  111. } else {
  112. this.close();
  113. }
  114. },
  115. immediate: true
  116. },
  117. /**
  118. * 监听type类型
  119. */
  120. type: {
  121. handler: function(type) {
  122. if (!this.config[type])
  123. return;
  124. this[this.config[type]](true);
  125. },
  126. immediate: true
  127. },
  128. isDesktop: {
  129. handler: function(newVal) {
  130. if (!this.config[newVal])
  131. return;
  132. this[this.config[this.type]](true);
  133. },
  134. immediate: true
  135. },
  136. /**
  137. * 监听遮罩是否可点击
  138. * @param {Object} val
  139. */
  140. maskClick: {
  141. handler: function(val) {
  142. this.mkclick = val;
  143. },
  144. immediate: true
  145. },
  146. isMaskClick: {
  147. handler: function(val) {
  148. this.mkclick = val;
  149. },
  150. immediate: true
  151. },
  152. // H5 下禁止底部滚动
  153. showPopup(show) {
  154. }
  155. },
  156. data() {
  157. return {
  158. sheep: sheep_index.sheep,
  159. duration: 300,
  160. ani: [],
  161. showPopup: false,
  162. showTrans: false,
  163. popupWidth: 0,
  164. popupHeight: 0,
  165. config: {
  166. top: "top",
  167. bottom: "bottom",
  168. center: "center",
  169. left: "left",
  170. right: "right",
  171. message: "top",
  172. dialog: "center",
  173. share: "bottom"
  174. },
  175. maskClass: {
  176. position: "fixed",
  177. bottom: 0,
  178. top: 0,
  179. left: 0,
  180. right: 0,
  181. backgroundColor: "rgba(0, 0, 0, 0.4)"
  182. },
  183. transClass: {
  184. position: "fixed",
  185. left: 0,
  186. right: 0
  187. },
  188. maskShow: true,
  189. mkclick: true,
  190. popupstyle: this.isDesktop ? "fixforpc-top" : "top"
  191. };
  192. },
  193. computed: {
  194. isDesktop() {
  195. return this.popupWidth >= 500 && this.popupHeight >= 500;
  196. },
  197. bg() {
  198. if (this.backgroundColor === "" || this.backgroundColor === "none") {
  199. return "transparent";
  200. }
  201. return this.backgroundColor;
  202. },
  203. borderRadius() {
  204. if (this.round) {
  205. if (this.type === "bottom") {
  206. return {
  207. "border-top-left-radius": parseFloat(this.round) + "px",
  208. "border-top-right-radius": parseFloat(this.round) + "px"
  209. };
  210. }
  211. if (this.type === "center") {
  212. return {
  213. "border-top-left-radius": parseFloat(this.round) + "px",
  214. "border-top-right-radius": parseFloat(this.round) + "px",
  215. "border-bottom-left-radius": parseFloat(this.round) + "px",
  216. "border-bottom-right-radius": parseFloat(this.round) + "px"
  217. };
  218. }
  219. if (this.type === "top") {
  220. return {
  221. "border-bottom-left-radius": parseFloat(this.round) + "px",
  222. "border-bottom-right-radius": parseFloat(this.round) + "px"
  223. };
  224. }
  225. }
  226. }
  227. },
  228. mounted() {
  229. const fixSize = () => {
  230. const { windowWidth, windowHeight, windowTop, safeArea, screenHeight, safeAreaInsets } = sheep_index.sheep.$platform.device;
  231. this.popupWidth = windowWidth;
  232. this.popupHeight = windowHeight + (windowTop || 0);
  233. if (safeArea && this.safeArea) {
  234. this.safeAreaInsets = screenHeight - safeArea.bottom;
  235. } else {
  236. this.safeAreaInsets = 0;
  237. }
  238. };
  239. fixSize();
  240. },
  241. // TODO vue3
  242. unmounted() {
  243. this.setH5Visible();
  244. },
  245. created() {
  246. if (this.isMaskClick === null && this.maskClick === null) {
  247. this.mkclick = true;
  248. } else {
  249. this.mkclick = this.isMaskClick !== null ? this.isMaskClick : this.maskClick;
  250. }
  251. if (this.animation) {
  252. this.duration = 300;
  253. } else {
  254. this.duration = 0;
  255. }
  256. this.messageChild = null;
  257. this.clearPropagation = false;
  258. this.maskClass.backgroundColor = this.maskBackgroundColor;
  259. },
  260. methods: {
  261. setH5Visible() {
  262. },
  263. /**
  264. * 公用方法,不显示遮罩层
  265. */
  266. closeMask() {
  267. this.maskShow = false;
  268. },
  269. /**
  270. * 公用方法,遮罩层禁止点击
  271. */
  272. disableMask() {
  273. this.mkclick = false;
  274. },
  275. // TODO nvue 取消冒泡
  276. clear(e) {
  277. e.stopPropagation();
  278. this.clearPropagation = true;
  279. },
  280. open(direction) {
  281. if (this.showPopup) {
  282. clearTimeout(this.timer);
  283. this.showPopup = false;
  284. }
  285. let innerType = ["top", "center", "bottom", "left", "right", "message", "dialog", "share"];
  286. if (!(direction && innerType.indexOf(direction) !== -1)) {
  287. direction = this.type;
  288. }
  289. if (!this.config[direction]) {
  290. console.error("缺少类型:", direction);
  291. return;
  292. }
  293. this[this.config[direction]]();
  294. this.$emit("change", {
  295. show: true,
  296. type: direction
  297. });
  298. },
  299. close(type) {
  300. this.showTrans = false;
  301. this.$emit("change", {
  302. show: false,
  303. type: this.type
  304. });
  305. this.$emit("close");
  306. clearTimeout(this.timer);
  307. this.timer = setTimeout(() => {
  308. this.showPopup = false;
  309. }, 300);
  310. },
  311. // TODO 处理冒泡事件,头条的冒泡事件有问题 ,先这样兼容
  312. touchstart() {
  313. this.clearPropagation = false;
  314. },
  315. onTap() {
  316. if (this.clearPropagation) {
  317. this.clearPropagation = false;
  318. return;
  319. }
  320. this.$emit("maskClick");
  321. if (!this.mkclick)
  322. return;
  323. this.close();
  324. },
  325. /**
  326. * 顶部弹出样式处理
  327. */
  328. top(type) {
  329. this.popupstyle = this.isDesktop ? "fixforpc-top" : "top";
  330. this.ani = ["slide-top"];
  331. this.transClass = {
  332. position: "fixed",
  333. left: 0,
  334. right: 0,
  335. top: this.space + "px",
  336. backgroundColor: this.bg
  337. };
  338. if (type)
  339. return;
  340. this.showPopup = true;
  341. this.showTrans = true;
  342. this.$nextTick(() => {
  343. if (this.messageChild && this.type === "message") {
  344. this.messageChild.timerClose();
  345. }
  346. });
  347. },
  348. /**
  349. * 底部弹出样式处理
  350. */
  351. bottom(type) {
  352. this.popupstyle = "bottom";
  353. this.ani = ["slide-bottom"];
  354. this.transClass = {
  355. position: "fixed",
  356. left: 0,
  357. right: 0,
  358. bottom: 0,
  359. paddingBottom: this.safeAreaInsets + this.space + "px",
  360. backgroundColor: this.bg
  361. };
  362. if (type)
  363. return;
  364. this.showPopup = true;
  365. this.showTrans = true;
  366. },
  367. /**
  368. * 中间弹出样式处理
  369. */
  370. center(type) {
  371. this.popupstyle = "center";
  372. this.ani = ["zoom-out", "fade"];
  373. this.transClass = {
  374. position: "fixed",
  375. display: "flex",
  376. flexDirection: "column",
  377. bottom: 0,
  378. left: 0,
  379. right: 0,
  380. top: 0,
  381. justifyContent: "center",
  382. alignItems: "center"
  383. };
  384. if (type)
  385. return;
  386. this.showPopup = true;
  387. this.showTrans = true;
  388. },
  389. left(type) {
  390. this.popupstyle = "left";
  391. this.ani = ["slide-left"];
  392. this.transClass = {
  393. position: "fixed",
  394. left: 0,
  395. bottom: 0,
  396. top: 0,
  397. backgroundColor: this.bg,
  398. display: "flex",
  399. flexDirection: "column"
  400. };
  401. if (type)
  402. return;
  403. this.showPopup = true;
  404. this.showTrans = true;
  405. },
  406. right(type) {
  407. this.popupstyle = "right";
  408. this.ani = ["slide-right"];
  409. this.transClass = {
  410. position: "fixed",
  411. bottom: 0,
  412. right: 0,
  413. top: 0,
  414. backgroundColor: this.bg,
  415. display: "flex",
  416. flexDirection: "column"
  417. };
  418. if (type)
  419. return;
  420. this.showPopup = true;
  421. this.showTrans = true;
  422. }
  423. }
  424. };
  425. const __injectCSSVars__ = () => {
  426. common_vendor.useCssVars((_ctx) => ({
  427. "2741299f": _ctx.backgroundImage
  428. }));
  429. };
  430. const __setup__ = __default__.setup;
  431. __default__.setup = __setup__ ? (props, ctx) => {
  432. __injectCSSVars__();
  433. return __setup__(props, ctx);
  434. } : __injectCSSVars__;
  435. const _sfc_main = __default__;
  436. if (!Array) {
  437. const _easycom_uni_transition2 = common_vendor.resolveComponent("uni-transition");
  438. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  439. (_easycom_uni_transition2 + _easycom_uni_icons2)();
  440. }
  441. const _easycom_uni_transition = () => "../../../uni_modules/uni-transition/components/uni-transition/uni-transition.js";
  442. const _easycom_uni_icons = () => "../../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  443. if (!Math) {
  444. (_easycom_uni_transition + _easycom_uni_icons)();
  445. }
  446. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  447. return common_vendor.e({
  448. a: $data.showPopup
  449. }, $data.showPopup ? common_vendor.e({
  450. b: $data.maskShow
  451. }, $data.maskShow ? {
  452. c: common_vendor.o($options.onTap),
  453. d: common_vendor.p({
  454. name: "mask",
  455. ["mode-class"]: "fade",
  456. styles: $data.maskClass,
  457. duration: $data.duration,
  458. show: $data.showTrans
  459. })
  460. } : {}, {
  461. e: $data.showPopup
  462. }, $data.showPopup ? common_vendor.e({
  463. f: $props.showClose
  464. }, $props.showClose ? {
  465. g: common_vendor.o($options.close),
  466. h: common_vendor.p({
  467. color: "#F6F6F6",
  468. type: "closeempty",
  469. size: "32"
  470. })
  471. } : {}, {
  472. i: common_vendor.s({
  473. backgroundColor: $options.bg
  474. }),
  475. j: common_vendor.s($options.borderRadius),
  476. k: common_vendor.n($data.popupstyle),
  477. l: common_vendor.o((...args) => $options.clear && $options.clear(...args))
  478. }) : {}, {
  479. m: common_vendor.o($options.onTap),
  480. n: common_vendor.p({
  481. ["mode-class"]: $data.ani,
  482. name: "content",
  483. styles: {
  484. ...$data.transClass,
  485. ...$options.borderRadius
  486. },
  487. duration: $data.duration,
  488. show: $data.showTrans
  489. }),
  490. o: common_vendor.o((...args) => $options.touchstart && $options.touchstart(...args)),
  491. p: common_vendor.n($data.popupstyle),
  492. q: common_vendor.n($options.isDesktop ? "fixforpc-z-index" : ""),
  493. r: common_vendor.s({
  494. zIndex: $props.zIndex
  495. }),
  496. s: common_vendor.s(_ctx.__cssVars()),
  497. t: common_vendor.o((...args) => $options.clear && $options.clear(...args))
  498. }) : {
  499. v: common_vendor.s(_ctx.__cssVars())
  500. });
  501. }
  502. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/sheep/ui/su-popup/su-popup.vue"]]);
  503. wx.createComponent(Component);