| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- const fs = require('fs');
- const path = 'd:/front-end/hdApp/src/admin/home/workbench.vue';
- let content = fs.readFileSync(path, 'utf8');
- // Remove duplicate template junk between first </template> and <script>
- content = content.replace(/<\/template>\s*<!--REMOVE_GHS_START-->[\s\S]*?<\/template>\s*<script>/, '</template>\n<script>');
- // Trim styles: keep only login styles (after <style> until .order-page)
- content = content.replace(
- /(<style lang="scss" scoped>[\s\S]*?\.login-register-link \{[\s\S]*?\})\s*\.order-page[\s\S]*<\/style>/,
- '$1\n</style>'
- );
- const scriptStart = content.indexOf('<script>');
- const styleStart = content.indexOf('<style');
- const scriptPart = content.slice(scriptStart, styleStart);
- const newScript = `<script>
- import { mapGetters } from "vuex";
- import { getWeixinId } from "@/api/invite";
- import autoUpdateMixins from "@/mixins/autoUpdate";
- import NotLogin from "@/components/not-login";
- import PurchaseGhsPanel from "./components/purchase-ghs-panel.vue";
- import MallHomePanel from "./components/mall-home-panel.vue";
- import { iconSrc } from "@/utils/iconSrc";
- export default {
- name: "workbench",
- components: { NotLogin, PurchaseGhsPanel, MallHomePanel },
- mixins: [autoUpdateMixins],
- data() {
- return {
- constant: this.$constant,
- getappIdList: {},
- loginStyle: 0,
- statusBarHeight: 0
- };
- },
- computed: {
- ...mapGetters({ loginInfo: "getLoginInfo" })
- },
- watch: {
- loginInfo(newVal) {
- if (!this.$util.isEmpty(newVal.admin) && newVal.admin.currentShopId > 0) {
- this.handleLoginModel(newVal);
- }
- }
- },
- onPullDownRefresh() {
- this.forwardToActivePanel("handlePullDownRefresh");
- },
- onLoad() {
- try {
- const systemInfo = uni.getSystemInfoSync();
- this.statusBarHeight = systemInfo.statusBarHeight || 0;
- } catch (e) {
- this.statusBarHeight = 0;
- }
- getWeixinId().then(res => {
- this.getappIdList = res.data;
- });
- this.$nextTick(() => {
- const panel = this.$refs.mallPanel;
- if (panel && panel.handlePageLoad) {
- panel.handlePageLoad();
- }
- });
- },
- onShow() {
- if (!this.$util.isEmpty(this.loginInfo.admin) && this.loginInfo.admin.currentShopId > 0) {
- this.handleLoginModel(this.loginInfo);
- } else {
- this.loginStyle = 0;
- }
- this.$nextTick(() => {
- this.forwardToActivePanel("handlePageShow");
- });
- },
- onShareAppMessage(res) {
- if (this.loginStyle === 1 && this.$refs.ghsPanel) {
- const msg = this.$refs.ghsPanel.getShareMessage(res);
- if (msg) return msg;
- }
- if (this.loginStyle === 2 && this.$refs.mallPanel) {
- return this.$refs.mallPanel.getShareMessage(res);
- }
- return { title: "花掌柜,花店管家婆", desc: "", imageUrl: "", path: "admin/home/workbench" };
- },
- methods: {
- iconSrc,
- forwardToActivePanel(methodName) {
- if (this.loginStyle === 1 && this.$refs.ghsPanel && this.$refs.ghsPanel[methodName]) {
- return this.$refs.ghsPanel[methodName]();
- }
- if (this.loginStyle === 2 && this.$refs.mallPanel && this.$refs.mallPanel[methodName]) {
- return this.$refs.mallPanel[methodName]();
- }
- if (methodName === "handlePullDownRefresh") {
- uni.stopPullDownRefresh();
- }
- },
- buyItem() {
- const that = this;
- // #ifdef MP-WEIXIN
- uni.navigateToMiniProgram({
- appId: that.getappIdList.mall.miniAppId,
- path: "pages/home/recent",
- envVersion: process.env.NODE_ENV === "development" ? "develop" : "release",
- extraData: {},
- success() {}
- });
- // #endif
- // #ifdef APP-PLUS
- that.$msg("请用微信打开");
- // #endif
- },
- handleLoginModel(info) {
- if (info.onlyCg == 1) {
- this.loginStyle = 1;
- uni.hideTabBar();
- this.$nextTick(() => {
- if (this.$refs.ghsPanel) {
- this.$refs.ghsPanel.handlePageShow();
- this.$refs.ghsPanel.toRemindCustom();
- }
- });
- } else {
- this.loginStyle = 2;
- uni.showTabBar();
- this.$nextTick(() => {
- if (this.$refs.mallPanel) {
- if (this.$refs.mallPanel.handlePageLoad) {
- this.$refs.mallPanel.handlePageLoad();
- }
- this.$refs.mallPanel.handlePageShow();
- }
- });
- }
- }
- }
- };
- </script>
- `;
- const stylePart = content.slice(styleStart);
- content = content.slice(0, scriptStart) + newScript + stylePart;
- fs.writeFileSync(path, content);
- console.log('trimmed workbench');
|