trim-workbench.js 4.5 KB

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