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