su-popup.js 14 KB

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