trim-order.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const fs = require('fs');
  2. const path = 'd:/front-end/hdApp/src/pagesPurchase/order.vue';
  3. let content = fs.readFileSync(path, 'utf8');
  4. content = content.replace(
  5. /<block v-else>[\s\S]*?<\/uni-popup>\s*\n\n\n <\/view>\n<\/template>/,
  6. `<block v-else>
  7. <purchase-ghs-panel ref="ghsPanel" :statusBarHeight="statusBarHeight" />
  8. </block>
  9. </view>
  10. </template>`
  11. );
  12. content = content.replace(
  13. /(<style lang="scss" scoped>[\s\S]*?\.login-register-link \{[\s\S]*?\})\s*\.order-page[\s\S]*<\/style>/,
  14. '$1\n</style>'
  15. );
  16. const scriptStart = content.indexOf('<script>');
  17. const styleStart = content.indexOf('<style');
  18. const newScript = `<script>
  19. import { mapGetters } from "vuex";
  20. import { getWeixinId } from "@/api/invite";
  21. import autoUpdateMixins from "@/mixins/autoUpdate";
  22. import PurchaseGhsPanel from "@/admin/home/components/purchase-ghs-panel.vue";
  23. import { iconSrc } from "@/utils/iconSrc";
  24. export default {
  25. name: "purchaseOrder",
  26. components: { PurchaseGhsPanel },
  27. mixins: [autoUpdateMixins],
  28. data() {
  29. return {
  30. constant: this.$constant,
  31. getappIdList: {},
  32. loginStyle: 0,
  33. statusBarHeight: 0
  34. };
  35. },
  36. computed: {
  37. ...mapGetters({ loginInfo: "getLoginInfo" })
  38. },
  39. watch: {
  40. loginInfo(newVal) {
  41. if (!this.$util.isEmpty(newVal.admin) && newVal.admin.currentShopId > 0) {
  42. this.handleLoginStyle();
  43. }
  44. }
  45. },
  46. onPullDownRefresh() {
  47. if (this.loginStyle === 1 && this.$refs.ghsPanel) {
  48. this.$refs.ghsPanel.handlePullDownRefresh();
  49. return;
  50. }
  51. uni.stopPullDownRefresh();
  52. },
  53. onLoad() {
  54. try {
  55. const systemInfo = uni.getSystemInfoSync();
  56. this.statusBarHeight = systemInfo.statusBarHeight || 0;
  57. } catch (e) {
  58. this.statusBarHeight = 0;
  59. }
  60. getWeixinId().then(res => {
  61. this.getappIdList = res.data;
  62. });
  63. },
  64. onShow() {
  65. if (!this.$util.isEmpty(this.loginInfo.admin) && this.loginInfo.admin.currentShopId > 0) {
  66. this.handleLoginStyle();
  67. this.$nextTick(() => {
  68. if (this.$refs.ghsPanel) {
  69. this.$refs.ghsPanel.handlePageShow();
  70. }
  71. });
  72. } else {
  73. this.loginStyle = 0;
  74. }
  75. },
  76. onShareAppMessage(res) {
  77. if (this.$refs.ghsPanel) {
  78. const msg = this.$refs.ghsPanel.getShareMessage(res);
  79. if (msg) return msg;
  80. }
  81. return { title: "花掌柜,花店管家婆", desc: "", imageUrl: "", path: "pagesPurchase/order" };
  82. },
  83. methods: {
  84. iconSrc,
  85. buyItem() {
  86. const that = this;
  87. // #ifdef MP-WEIXIN
  88. uni.navigateToMiniProgram({
  89. appId: that.getappIdList.mall.miniAppId,
  90. path: "pages/home/recent",
  91. envVersion: process.env.NODE_ENV === "development" ? "develop" : "release",
  92. extraData: {},
  93. success() {}
  94. });
  95. // #endif
  96. // #ifdef APP-PLUS
  97. that.$msg("请用微信打开");
  98. // #endif
  99. },
  100. handleLoginStyle() {
  101. this.loginStyle = 1;
  102. this.$nextTick(() => {
  103. if (this.$refs.ghsPanel) {
  104. this.$refs.ghsPanel.toRemindCustom();
  105. }
  106. });
  107. }
  108. }
  109. };
  110. </script>
  111. `;
  112. const stylePart = content.slice(styleStart);
  113. content = content.slice(0, scriptStart) + newScript + stylePart;
  114. fs.writeFileSync(path, content);
  115. console.log('trimmed order.vue');