stack overflow at line:0

本文提供了pngfilt.dll文件丢失或损坏的解决方案,包括从指定网站下载该文件,并将其复制到不同版本Windows系统的相应目录中,最后通过运行命令完成修复。
打开百度地图的时候就来这个东西,后来从网上查了的。是你的pngfilt.dll文件损坏,从网上重新下载一个
提供个下载地址 http://www.duote.com/dll/pngfilt_dll.html
一、如果您的系统提示"找不到pngfilt.dll"或"pngfilt.dll缺失" 或者"pngfilt.dll错误"等等,请不用担心,请把pngfilt.dll下载到本机。
二、直接拷贝该文件到系统目录里:
   1、Windows 95/98/Me系统,将pngfilt.dll复制到C:WindowsSystem目录下。
   2、Windows NT/2000系统,将pngfilt.dll复制到C:WINNTSystem32目录下。
   3、Windows XP/WIN7系统,将pngfilt.dll复制到C:WindowsSystem32目录下。
三、然后打开"开始-运行-输入regsvr32 pngfilt.dll",回车即可解决错误提示!希望多特软件站为您提供的pngfilt.dll对您有所帮助!
<template> <div class="app-container table-page-content projectManage"> <div class="filter-container"> <el-form ref="queryForm" :inline="true" :model="listQuery" label-position="top" > <!-- 1. 部门默认二级部门,支持模糊搜索,支持清空 --> <!-- <el-form-item label="部门" prop="department"> <el-select v-model="listQuery.department" filterable clearable placeholder="请选择部门" > size="mini" <el-option v-for="item in departmentOptions" :key="item.code" :label="item.name" :value="item.name" /> </el-select> </el-form-item> --> <!-- :default-value="listQuery.defaultNode" --> <!-- :defaultExpandedKeys="setKey" --> <el-form-item label="部门" prop="tree" class="search-form-item"> <select-tree v-model="listQuery.tree" filterable :tree-options="departData" :default-value="defaultNode" :defaultProps="defaultProps" @onNodeSelectEvent="departmentCancel" /> </el-form-item> <el-form-item label="项目名称" prop="name" class="search-form-item"> <el-input v-model="listQuery.name" placeholder="项目名称/项目code" size="mini" /> </el-form-item> <el-form-item label="项目责任人" prop="owner" class="search-form-item"> <el-select v-model="listQuery.owner" :remote-method="getUsesLikeQuery" :loading="ownerLoading" placeholder="项目责任人" clearable filterable remote reserve-keyword size="mini" > <el-option v-for="item in ownerNameListOptions" :key="item.id" :label="item.nickname" :value="item.id" /> </el-select> </el-form-item> <el-form-item label="绑定队列" prop="queues" class="search-form-item"> <el-cascader v-model="listQuery.queues" :options="queuesOptions" filterable placeholder="请选择队列" clearable ></el-cascader> </el-form-item> <el-form-item label="项目成员" prop="members" class="search-form-item"> <el-select v-model="listQuery.members" :remote-method="getUsesLikeQuery" :loading="ownerLoading" placeholder="请选择成员姓名" clearable filterable remote reserve-keyword size="mini" > <el-option v-for="item in ownerNameListOptions" :key="item.id" :label="item.nickname" :value="item.id" /> </el-select> </el-form-item> <el-form-item label="状态" prop="projectCreateStatus" class="search-form-item" > <el-select v-model="listQuery.projectCreateStatus" placeholder="请选择项目状态" clearable size="mini" > <el-option v-for="item in projectCreateStatusOptions" :key="item" :label="projectStatusType[item]" :value="item" /> </el-select> </el-form-item> <!-- <el-form-item label=""> </el-form-item> --> <el-form-item label="" class="search-btns"> <el-button v-waves size="mini" type="primary" @click="handleFilter" >查询</el-button > <el-button v-waves size="mini" type="primary" plain @click="reset" >重置</el-button > </el-form-item> </el-form> </div> <div class="table-container resize"> <div class="toolbar-box"> <div class="toolbar-box-left"> <el-checkbox-group v-model="listQuery.range" class="role" @change="checkChange" size="mini" > <!-- <el-checkbox label="all">全部</el-checkbox> --> <el-checkbox label="manage">我管理的</el-checkbox> <el-checkbox label="attend">我参与的</el-checkbox> </el-checkbox-group> </div> <div class="toolbar-box-right"> <el-button v-waves size="mini" type="primary" @click="toNewProject" v-if="buttonIsAccess(ActionEnum.CREATE)" :loading="newProjectButtonLoading" > <span> <svg-icon icon-class="add" style="font-size: 12px; margin-right: 4px" v-if="!newProjectButtonLoading" /> 新建项目</span > </el-button> </div> </div> <el-table v-loading="listLoading" :data="list" :border="true" row-key="id" size="small" header-row-class-name="table-header" style="width: 100%" height="calc(100% - 48px)" highlight-current-row > <el-table-column label="项目空间编码" align="left" prop="code" show-overflow-tooltip min-width="180px" /> <el-table-column label="项目空间名称" align="left" prop="name" show-overflow-tooltip min-width="180px" /> <el-table-column label="项目ID" align="left" prop="id" show-overflow-tooltip min-width="120px" /> <el-table-column label="描述" align="left" prop="description" show-overflow-tooltip min-width="100px" /> <el-table-column label="项目空间模式" prop="projectMode" width="100px"> <template slot-scope="scope"> <span v-if="scope.row.projectMode === 1" class="project_mode_sta" >标准模式</span > <span v-else-if=" scope.row.projectMode === 0 || scope.row.projectMode === 2 " class="project_mode_sim" >简单模式</span > </template> </el-table-column> <el-table-column label="责任人" align="left" prop="ownerName" min-width="120px" show-overflow-tooltip /> <el-table-column label="状态" align="left" prop="description" show-overflow-tooltip min-width="70px" > <template slot-scope="scope"> <span v-if="scope.row.status === 0">禁用</span> <span v-if="scope.row.status === 1" style="color: #24c63a" >启用</span > <span v-if="scope.row.status === 2">待审批</span> <span v-if="scope.row.status === 3">审批完成</span> <span v-if="scope.row.status === 4" style="color: #ffa52e" >创建中</span > <span v-if="scope.row.status === 5" style="color: #ffa52e" >创建失败</span > </template> </el-table-column> <el-table-column label="创建时间" align="left" prop="createTime" width="150px" /> <el-table-column fixed="right" label="操作" align="left" class-name="small-padding" width="270px" > <template slot-scope="scope"> <el-button v-if=" (buttonIsAccess(ActionEnum.DETAIL) || (scope.row.userRoles && scope.row.userRoles.length > 0)) && scope.row.status !== 4 && scope.row.status !== 5 " type="text" title="" @click="toViewProject(scope.row)" > 详情 </el-button> <el-button v-if=" (!scope.row.userRoles || (scope.row.userRoles && scope.row.userRoles.length === 0)) && scope.row.status !== 4 && scope.row.status !== 5 " type="text" title="" @click="handleProject(scope.row, 'join')" > 申请 </el-button> <el-button v-if="scope.row.status === 4 || scope.row.status === 5" type="text" @click="handleProjectProgress(scope.row)" > 查看进度 </el-button>    <el-dropdown v-if=" ((scope.row.userRoles && scope.row.userRoles.length > 0) || buttonIsAccess(ActionEnum.ENTER)) && scope.row.status !== 4 && scope.row.status !== 5 " @command="toPage" > <span class="el-dropdown-link"> 进入<i class="el-icon-arrow-down el-icon--right" /> </span> <el-dropdown-menu slot="dropdown"> <el-dropdown-item v-for="(button, index) in buttonMapping" :key="index" :command="{ path: button.path, project: scope.row }" >{{ button.text }}</el-dropdown-item > <!-- 暂时禁用去数据集成的按钮,等页面迁移完成 --> </el-dropdown-menu> </el-dropdown>    <el-button v-if=" (isProjectOwner(scope.row) || buttonIsAccess(ActionEnum.OFFLINE)) && scope.row.status !== 4 && scope.row.status !== 5 " type="text" @click="offlineCheck(scope.row, 'offline')" :loading="offlineLoading === scope.row.id" > 下线 </el-button> <el-button v-if=" buttonIsAccess(ActionEnum.CONFIG) && scope.row.status !== 4 && scope.row.status !== 5 " type="text" @click="handleProject(scope.row, 'platformEdit')" > 平台设置 </el-button> </template> </el-table-column> </el-table> </div> <div class="pagination-container"> <el-pagination v-show="total > 0" :current-page="listQuery.pageNum" :page-sizes="[10, 20, 50, 100]" :page-size="listQuery.pageSize" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange" /> </div> <JoinProject :visible="visible" :project="currentProject" @close="handleClose" /> <Offline :visible="visible" :project="currentProject" @close="handleClose" /> <PlatformEdit :visible="visible" :project="currentProject" @close="handleClose" /> <NewProjectPrompt :visible="newProjectPromptVisible" :info="queueAndprojectInfo" @close="handleClose" @toSearchProject="projectSearch" @toSearchQueues="queuesSearch" /> <QueueSearch v-if="queueSearchVisible" :q-select-visible.sync="queueSearchVisible" :resourcePools1="resourcePools1" :resourcePools2="resourcePools2" :resourcePools3="resourcePools3" /> <offlineCheck :visible="offlineCheckModalStatus" :project="currentProject" :check-info="checkInfo" @close="offlineCheckhandleClose" @openOffline="openOfflineModal" /> <CreateProgress v-if="progressVisible" :visible="progressVisible" :project="progressCurrentProject" @close="handleClose" /> </div> </template> <script> import { mapGetters } from "vuex"; import { querySysUserVoList, createOwnerCheck, getLayer, getOwner, offlienCheck, getAllQueueInfo, getProjectStatus, } from "@/api/ops"; import { queryProjectList, reqDepartmentPerson } from "@/api/prospace"; import { reqDepartmentTree } from "@/api/index"; import waves from "@/directive/waves"; // 水波纹指令 import JoinProject from "./joinProject.vue"; import NewProjectPrompt from "./newProjectPrompt.vue"; import offlineCheck from "./offlineCheck.vue"; import Offline from "./offline.vue"; import PlatformEdit from "./platformEdit.vue"; import CreateProgress from "./createProgress.vue"; import buttonIsAccess from "@/mixins/buttonIsAccess.js"; import SelectTree from "./selectTree.vue"; import { ActionEnum, sceneType, reSceneType, projectStatusType, } from "./enum.js"; import QueueSearch from "./queueSearch.vue"; import { getRealClusters } from "@/api/rtcpapi"; export default { name: "Project", components: { JoinProject, Offline, PlatformEdit, NewProjectPrompt, QueueSearch, offlineCheck, CreateProgress, SelectTree, }, mixins: [buttonIsAccess], directives: { waves, }, data() { return { defaultProps: { children: "nodes", label: "name", value: "name", }, departData: [], reSceneType, projectStatusType, ActionEnum, sceneType, buttonMapping: Object.freeze([ { text: "数据查询", path: "/data/data-query", }, { text: "开发中心", path: "/devcenter/datadev", }, { text: "运维中心", path: "/dataopsv/ops/task", }, { text: "数据集成", path: "/discenter/didsppage/didspOverview", }, ]), visible: "", newProjectPromptVisible: false, // 新建项目的提示modal框状态 newProjectButtonLoading: false, // 新建项目按钮判断期间的状态 queueAndprojectInfo: { checkType: undefined, projectInfo: 0, queueInfo: 0, department: undefined, }, // 当前用户的队列和所在部门的项目信息 queueSearchVisible: false, // 查询队列抽屉展开状态 departmentOptions: [], departmentOptions2: [], selectedId: "", ownerLoading: false, pickerOptions: { shortcuts: [ { text: "今天内", onClick(picker) { picker.$emit("pick", [new Date(), new Date()]); }, }, { text: "最近2天", onClick(picker) { const end = new Date(); const start = new Date(); start.setDate(new Date().getDate() - 1); picker.$emit("pick", [start, end]); }, }, { text: "最近5天", onClick(picker) { const end = new Date(); const start = new Date(); start.setDate(new Date().getDate() - 4); picker.$emit("pick", [start, end]); }, }, ], }, list: [], total: null, listLoading: false, listQuery: { pageNum: 1, pageSize: 20, code: null, projectMode: "", name: null, owner: undefined, department: "", editDay: [], range: ["attend", "manage"], members: "", tree: { node: "", data: {} }, queues: [], projectCreateStatus: undefined, }, defaultNode: "", projectList: [], ownerNameListOptions: [], projectCreateStatusOptions: [], envirenmentIsolateList: [ { id: 1, name: "标准模式" }, { id: 2, name: "简单模式" }, ], currentProject: {}, department: "", hasJoin: false, resourcePools1: [], resourcePools2: [], resourcePools3: [], offlineCheckModalStatus: false, checkInfo: {}, offlineLoading: null, progressVisible: false, progressCurrentProject: {}, selectValue: "", queuesOptions: [], }; }, mounted() { // 模拟接口请求,反显选择数据 // setTimeout(() => { // this.listQuery.tree.node = "部门001"; // }, 2000); // const params = new URLSearchParams(window.location.search); // this.listQuery.tree.node = "部门001"; }, computed: { ...mapGetters({ userName: "name", userId: "userid", email: "userEmail", }), }, created() { sessionStorage.removeItem("verify"); const params = new URLSearchParams(window.location.search); console.log("params", Object.fromEntries(params)); const objectParams = Object.fromEntries(params); delete objectParams.projectStatus; console.log("params1", objectParams); if (params.get("isApply") !== null) { this.listQuery.range = ["all"]; } if (params.get("range")) { if (params.get("range") == "all") { this.listQuery.range = []; } else { this.listQuery.range = params.get("range").split(","); } } if (params.get("proId")) { this.listQuery.id = params.get("proId"); } // if (params.get("department")) { // this.listQuery.department = params.get("department"); // } if (params.get("projectName")) { this.listQuery.name = params.get("projectName"); // this.handleFilter(); } if (params.get("projectStatus")) { this.listQuery.projectCreateStatus = Number(params.get("projectStatus")); } // 请求部门的树型结构数据 reqDepartmentTree().then((res) => { this.departmentOptions = this.convertTreeToArray(res.data.nodes); // this.departData = [res.data]; this.departData = res.data.nodes; if (params.get("department")) { this.defaultNode = params.get("department"); // this.listQuery.tree.node = params.get("department"); } }); // 请求项目状态选择项数据 getProjectStatus().then((res) => { this.projectCreateStatusOptions = res.data; console.log("statusres", res.data); }); // 请求项目筛选项数据 getAllQueueInfo().then((res) => { this.queuesOptions = this.queueTransfromData(res.data); }); this.handleFilter(); // this.listLoading = true; // reqDepartmentPerson() // .then((res) => { // if (params.get("department") !== null && params.get("range") !== null) { // this.department = res.data["departments"]["一级部门"]; // this.listQuery.department = this.department; // this.listQuery.range = [params.get("range")]; // } else { // this.department = ""; // } // // this.department = res.data['departments']['三级部门'] || res.data.deptName // // this.listQuery.department =this.department // this.handleFilter(); // }) // .catch(() => { // this.handleFilter(); // }); this.getResourcePool(); }, watch() { }, mounted() { const params = new URLSearchParams(window.location.search); // 判断是否自动验证新建项目的权限 if (params.get("newPrejectVerify")) { this.toNewProject(); this.$router.push({ query: {}, }); } }, methods: { // 清空树选项 departmentCancel(result) { this.defaultNode = ""; }, // 树型项目搜索方法 filterNode(value, data) { if (!value) return true; return data.fullName.toLowerCase().indexOf(value.toLowerCase()) !== -1; }, // 树型项目搜索方法 filterOrg(val) { this.$refs.orgTree.filter(val || ""); return true; }, queueTransfromData(inputData) { return inputData.map((item) => { // 处理父级节点 const parentNode = { value: `${item.catalogName} (${sceneType[item.scene]})`, // 转换为小写并替换特殊字符 label: `${item.catalogName} (${sceneType[item.scene]})`, // scene: item.scene, children: [], }; // 处理子级节点 const queueData = item.queueVos || item.queueVos || []; parentNode.children = queueData.map((queue) => ({ value: queue.name, label: queue.name, })); return parentNode; }); }, throwMsg(res) { Notification.error({ title: "获取元目录资源错误", message: res.msg, copyObj: response, }); }, // 请求元目录选项信息 getResourcePool() { getRealClusters({ scene: 1 }) // 离线 .then((res) => { if (res.code !== 0) { this.throwMsg(); return; } this.resourcePools1 = res.data; }); getRealClusters({ scene: 2 }).then((res) => { //实时集成 if (res.code !== 0) { this.throwMsg(); return; } this.resourcePools2 = res.data; }); getRealClusters({ scene: 3 }).then((res) => { // 实时计算 if (res.code !== 0) { this.throwMsg(); return; } this.resourcePools3 = res.data; }); }, queuesSearch() { this.queueSearchVisible = true; }, projectSearch() { this.listQuery.range = []; this.defaultNode = this.queueAndprojectInfo.department; this.listQuery.tree.node = this.queueAndprojectInfo.department; this.handleFilter(); }, // 递归处理树级部门 convertTreeToArray(nodes) { const result = []; const stack = [...nodes]; while (stack.length) { const node = stack.pop(); result.push(node); if (node.nodes && node.nodes.length > 0) { stack.push(...node.nodes); } } return result.reverse(); }, selectDepartment(val) { this.listQuery.department = val ? val[val.length - 1] : ""; }, toPage(command) { sessionStorage.setItem("project", JSON.stringify(command.project)); const origin = window.location.origin; window.open( `${origin}${command.path}?projectId=${command.project.id}`, "_blank" ); }, handleClose() { this.visible = ""; this.newProjectPromptVisible = false; this.progressVisible = false; delete this.listQuery.id; }, /** * 是否是项目管理员或责任人 * @param {*} row */ isProjectOwner(row) { if ( row.currentUserProjectRoleNames && (row.currentUserProjectRoleNames.indexOf("项目空间项目管理员") > -1 || row.currentUserProjectRoleNames.indexOf("项目空间项目责任人") > -1) ) { return true; } return false; }, reset() { this.$refs["queryForm"].resetFields(); this.listQuery.department = this.department; this.handleFilter(); }, // 条件过滤 handleFilter() { this.listQuery.pageNum = 1; this.getList(); }, // 勾选查询 checkChange() { this.listQuery.pageNum = 1; this.getList(); }, //列表查询 getList() { // this.listLoading = true; const params = new URLSearchParams(window.location.search); const query = Object.assign({}, this.listQuery); // if (query.projectMode === 2) delete query.projectMode if (this.listQuery.editDay && this.listQuery.editDay.length === 2) { query.updateTimeStart = `${this.listQuery.editDay[0]} 00:00:00`; query.updateTimeEnd = `${this.listQuery.editDay[1]} 23:59:59`; } if (query.queues.length) { query.queueCatalog = query.queues[0].split(" ")[0]; // 元目录名 query.searchQueues = query.queues[1]; // 队列名 query.scene = this.reSceneType[query.queues[0].replace(/^.*\((.*)\).*$/, "$1")]; // 队列用途类型 } if ( params.get("department") && !query.tree.node && query.tree.node !== undefined ) { query.department = params.get("department"); } else { query.department = query.tree.node; } delete query.editDay; delete query.queues; delete query.tree; // if (!query.range.includes('manage') && !query.range.includes('attend') && !query.range.includes('all')) { // query.range.push('all') // } query.isGetcurrentUserProjectRoleNames = 1; //代表获取当前登录人加入的项目对应的角色信息 queryProjectList({ ...query, range: query.range.includes("all") ? "all" : query.range.join(",") === "" ? "all" : query.range.join(","), }) .then((response) => { this.listLoading = false; this.list = response.data.list; this.total = response.data.total; // 关于查询字符串中pageType的逻辑判断 this.handleModal( (response.data && response.data.list && response.data.list[0]) || undefined ); }) .catch((error) => { this.listLoading = false; }); }, //查询用户 getUsesLikeQuery(name) { if (name && name.length > 0) { this.ownerLoading = true; this.ownerNameListOptions = []; querySysUserVoList({ value: name }) .then((res) => { this.ownerNameListOptions = [...res.data]; this.ownerLoading = false; }) .catch(() => { this.ownerLoading = false; }); } }, //查看项目 toViewProject(choose_project) { sessionStorage.setItem("project", JSON.stringify(choose_project)); const origin = window.location.origin; window.open( `${origin}/dataopsv/res/project-detail?projectId=${choose_project.id}` ); }, handleSizeChange(val) { this.listQuery.pageSize = val; this.getList(); }, handleCurrentChange(val) { this.listQuery.pageNum = val; this.getList(); }, // 新建项目 toNewProject(e) { this.newProjectButtonLoading = true; // 创建项目owner校验 createOwnerCheck() .then((res) => { // 1 - 属于队列owner且三级部门下无项目; // 2 - 属于队列owner且三级部门下有项目; // 3 - 不属于队列owner; this.$set( this.queueAndprojectInfo, "checkType", res.data.checkResult ); if (res.data.checkResult == 1) { window.sessionStorage.setItem("verify", "success"); location.href = "/dataopsv/project-space/ps-list/project-create"; } else { Promise.all([ getLayer({ email: this.email, layer: 3 }).then((response) => { this.$set( this.queueAndprojectInfo, "department", response.data ); queryProjectList({ pageNum: 1, pageSize: 10, department: response.data, }).then((response) => { this.$set( this.queueAndprojectInfo, "projectInfo", response.data.total ); }); }), getOwner({ email: this.email }).then((response) => { this.$set( this.queueAndprojectInfo, "queueInfo", response.data.total ); }), ]) .then(() => { // 所有请求完成后才执行 this.newProjectPromptVisible = true; this.newProjectButtonLoading = false; }) .catch(() => { this.newProjectButtonLoading = false; }); } }) .catch(() => { this.newProjectButtonLoading = false; }); // new Promise((resolve) => { // setTimeout(() => { // resolve({ // checkType: 1, // projectInfo: 1, // queueInfo: 2, // department: "部门003", // }); // }, 2000); // }).then((data) => { // // 这里做判断是否打开提示框 // this.queueAndprojectInfo = data; // if (data.checkType == 1) { // window.sessionStorage.setItem("verify", "success"); // location.href = "/dataopsv/project-space/ps-list/project-create"; // } else { // this.newProjectPromptVisible = true; // } // this.newProjectButtonLoading = false; // }); // location.href = "/dataopsv/project-space/ps-list/project-create"; }, // 下线检测 offlineCheck(row, type) { this.offlineLoading = row.id; offlienCheck({ projectId: row.id }).then((res) => { this.checkInfo = res.data; this.offlineCheckModalStatus = true; this.currentProject = row; this.offlineLoading = null; }); }, openOfflineModal() { this.offlineCheckModalStatus = false; this.visible = "offline"; }, offlineCheckhandleClose() { this.offlineCheckModalStatus = false; }, handleProject(row, type) { // 弹框 正常itsm流程 this.visible = type; this.currentProject = row; }, handleProjectProgress(row) { this.progressVisible = true; this.progressCurrentProject = row; }, handleModal(listDatas) { if (!this.hasJoin) { const params = new URLSearchParams(window.location.search); const type = params.get("pageType"); // 只对第一条数据进行相关操作 if (type && listDatas) { if ( // 申请加入项目空间 type === "join" && (!listDatas.userRoles || (listDatas.userRoles && listDatas.userRoles.length === 0)) ) { this.handleProject(listDatas, type); } } // else if ( // // 下线(预设) // type === "offline" && // (this.isProjectOwner(listDatas) || // this.buttonIsAccess(ActionEnum.OFFLINE)) // ) { // this.handleProject(listDatas, type); // } else if ( // // 平台设置(预设) // type === "platformEdit" && // this.buttonIsAccess(ActionEnum.CONFIG) // ) { // this.handleProject(listDatas, type); // } this.hasJoin = true; } }, }, }; </script> <style lang="scss" scoped> @import "@/styles/table.scss"; @import "@/styles/pagination-query.scss"; @import "@/styles/ui-style.scss"; @mixin pointColor($color) { font-size: 12px; width: fit-content; color: $color; &::before { content: "●"; font-size: 6px; color: $color; margin-right: 4px; } } ::v-deep .cell .el-button span { font-size: 12px; } ::v-deep .cell .el-button:not(.is-disabled) span { color: #006eff; font-size: 12px; } ::v-deep .cell .el-dropdown span { color: hsl(214, 100%, 50%); font-size: 12px; } .cell .button-text:not(.is-disabled) { color: #006eff; } .cell .button-text { font-size: 12px; } .app-container.table-page-content.projectManage { display: flex; flex-direction: column; .filter-container { border-radius: 4px; padding: 8px; .search-form-item { width: 12.5% !important; margin-right: 0 !important; padding-right: 4px; padding-left: 4px; min-width: 0 !important; } .search-btns { width: 12% !important; margin-left: 4px; } .search-btns .el-button + .el-button { margin-left: 2px; } ::v-deep .el-cascader { width: 100%; } ::v-deep .el-input, .el-select { width: 100%; } ::v-deep .el-form { display: flex; align-items: end; padding: 0px; // .el-select { // width: fit-content; // } .el-form-item__label { font-size: 12px; line-height: 20px; } .el-input__inner { height: 28px !important; line-height: 28px !important; } .search-btns { .el-button { height: 28px; padding: 0 15px; } } } background-color: #fff; ::v-deep .el-form-item--mini.el-form-item { margin-bottom: 2px !important; margin-right: 8px; } ::v-deep .el-checkbox-group { height: 28px; } ::v-deep .el-checkbox { height: 28px; margin-right: 12px; } // ::v-deep .el-input { // width: 160px; // } .custom-cascader .el-cascader-panel { display: none !important; } .more-serach-btn { cursor: pointer; position: absolute !important; right: 20px; top: 10px; z-index: 1; border-radius: 4px; border: 1px solid #006eff; color: #006eff; width: 98px; height: 32px; text-align: center; line-height: 32px; } .more-serach-btn.is-checked { background: #006eff; color: #fff; } min-height: 30px; /* padding-right: 120px; */ position: relative; ::v-deep .el-cascader--mini .el-input__inner { height: 28px !important; } ::v-deep .el-cascader--mini .el-input__inner_change { height: 59px !important; } // 树行项目样式 // .tree-container { // height: 240px; // overflow-y: auto; // background-color: #fff; // } // // ::v-deep { // .el-tree-node__content { // height: 32px; // font-weight: normal; // } // // .el-tree-node.is-current > .el-tree-node__content { // background-color: #f5f7fa; // color: #409eff; // } // } } .table-container { margin-top: 10px; padding: 0; flex: 1; .toolbar-box { padding: 8px; display: flex; align-items: center; justify-content: space-between; min-height: 48px; // display: flex; // justify-content: end; .toolbar-box-left { ::v-deep .el-checkbox-group { display: flex; .el-checkbox { margin-right: 8px; display: flex; align-items: center; } } } } ::v-deep .el-table--scrollable-x .el-table__body-wrapper { height: calc(100% - 40px) !important; } } .pagination-container { height: 48px; } .project_mode_sta { @include pointColor(#24c63a); } .project_mode_sim { @include pointColor(#ffa52e); } } </style> 上述代码中怎么监听this.listQuery.projectCreateStatus值得变化,让后做其他操作
08-14
on functions.php, it says Your PHP code changes were not applied due to an error on line 82 of file wp-content/themes/woodmart-child/functions.php. Please fix and try saving again. Uncaught TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, null given in wp-content/themes/woodmart-child/functions.php:82 Stack trace: #0 wp-content/themes/woodmart-child/functions.php(82): method_exists() #1 wp-includes/class-wp-hook.php(324): {closure}() #2 wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #3 wp-includes/plugin.php(517): WP_Hook->do_action() #4 wp-settings.php(749): do_action() #5 wp-config.php(105): require_once(‘/home/u18285596…’) #6 wp-load.php(50): require_once(‘/home/u18285596…’) #7 wp-admin/admin.php(35): require_once(‘/home/u18285596…’) #8 wp-admin/theme-editor.php(10): require_once(‘/home/u18285596…’) #9 {main} thrown cart.php <?php /** * Custom Cart Page for WooCommerce with Selective Checkout */ if (!defined('ABSPATH')) { exit; } do_action('woocommerce_before_cart'); // Provide context for JS (no layout change) $pc_cart_is_empty = WC()->cart->is_empty(); function pc_uid_for_view() { if (is_user_logged_in()) return 'user_' . get_current_user_id(); if (empty($_COOKIE['pc_cart_uid'])) { $token = wp_generate_uuid4(); setcookie('pc_cart_uid', $token, time() + YEAR_IN_SECONDS, COOKIEPATH ?: '/', '', is_ssl(), false); $_COOKIE['pc_cart_uid'] = $token; } return 'guest_' . sanitize_text_field(wp_unslash($_COOKIE['pc_cart_uid'])); } $pc_uid = pc_uid_for_view(); // 已修正:仅在令牌存在时恢复购物车 if (method_exists(WC()->session, 'get')) { $token = WC()->session->get('pc_partial_token'); if ($token && !WC()->cart->is_empty()) { $payload = get_transient(pc_transient_key($token)); if (!empty($payload['snapshot'])) { pc_restore_cart_from_items($payload['snapshot']); WC()->cart->calculate_totals(); } } } ?> <div class="cart-page-section container" style="max-width: 1200px; margin: 0 auto;"> <form class="woocommerce-cart-form" action="<?php echo esc_url( wc_get_cart_url() ); ?>" method="post"> <?php do_action('woocommerce_before_cart_table'); ?> <?php wp_nonce_field('woocommerce-cart', 'woocommerce-cart-nonce'); ?> <table class="shop_table shop_table_responsive cart woocommerce-cart-form__contents"> <thead> <tr> <th class="product-select" style="width: 8%;"> <input type="checkbox" id="select-all-items" /> <label for="select-all-items" style="display: inline-block; margin-left: 5px; cursor: pointer;">全选</label> </th> <th class="product-info"><?php esc_html_e('Product', 'woocommerce'); ?></th> <th class="product-price"><?php esc_html_e('Price', 'woocommerce'); ?></th> <th class="product-quantity"><?php esc_html_e('Quantity', 'woocommerce'); ?></th> <th class="product-subtotal"><?php esc_html_e('Subtotal', 'woocommerce'); ?></th> <th class="product-remove"><?php esc_html_e('操作', 'woocommerce'); ?></th> </tr> </thead> <tbody> <?php do_action('woocommerce_before_cart_contents'); ?> <?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) : ?> <?php $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key); if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters('woocommerce_cart_item_visible', true, $cart_item, $cart_item_key) ) : $product_permalink = apply_filters('woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink($cart_item) : '', $cart_item, $cart_item_key); $line_total_value = (float) ($cart_item['line_total'] + $cart_item['line_tax']); $variation_id = isset($cart_item['variation_id']) ? (int)$cart_item['variation_id'] : 0; $variation_data = isset($cart_item['variation']) ? $cart_item['variation'] : array(); $variation_json = wp_json_encode($variation_data); ?> <tr class="woocommerce-cart-form__cart-item <?php echo esc_attr( apply_filters('woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key) ); ?>" data-cart_item_key="<?php echo esc_attr($cart_item_key); ?>" data-product_id="<?php echo esc_attr($product_id); ?>" data-variation_id="<?php echo esc_attr($variation_id); ?>" data-variation="<?php echo esc_attr($variation_json); ?>"> <!-- Checkbox Column --> <td class="product-select" data-title="<?php esc_attr_e('Select', 'woocommerce'); ?>"> <input type="checkbox" class="item-checkbox" name="selected_items[]" value="<?php echo esc_attr($cart_item_key); ?>" data-price="<?php echo esc_attr($line_total_value); ?>" /> </td> <!-- Product Info Column --> <td class="product-info" data-title="<?php esc_attr_e('Product', 'woocommerce'); ?>"> <div class="product-image"> <?php $thumbnail = apply_filters('woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key); if ( ! $product_permalink ) : echo $thumbnail; // PHPCS: XSS ok. else : printf('<a href="%s">%s</a>', esc_url($product_permalink), $thumbnail); // PHPCS: XSS ok. endif; ?> </div> <div class="product-name"> <?php if ( ! $product_permalink ) : echo wp_kses_post( apply_filters('woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key) . ' ' ); else : echo wp_kses_post( apply_filters('woocommerce_cart_item_name', sprintf('<a href="%s">%s</a>', esc_url($product_permalink), $_product->get_name()), $cart_item, $cart_item_key) ); endif; do_action('woocommerce_after_cart_item_name', $cart_item, $cart_item_key); echo wc_get_formatted_cart_item_data($cart_item); // PHPCS: XSS ok. ?> </div> </td> <!-- Price Column --> <td class="product-price" data-title="<?php esc_attr_e('Price', 'woocommerce'); ?>"> <?php echo apply_filters('woocommerce_cart_item_price', WC()->cart->get_product_price($_product), $cart_item, $cart_item_key); // PHPCS: XSS ok. ?> </td> <!-- Quantity Column --> <td class="product-quantity" data-title="<?php esc_attr_e('Quantity', 'woocommerce'); ?>"> <?php if ( $_product->is_sold_individually() ) : $product_quantity = sprintf('1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key); else : $product_quantity = woocommerce_quantity_input( array( 'input_name' => "cart[{$cart_item_key}][qty]", 'input_value' => $cart_item['quantity'], 'max_value' => $_product->get_max_purchase_quantity(), 'min_value' => '0', 'product_name' => $_product->get_name(), ), $_product, false ); endif; echo apply_filters('woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item); // PHPCS: XSS ok. ?> <small class="qty-status" style="display:none;margin-left:8px;color:#666;">保存中…</small> </td> <!-- Subtotal Column --> <td class="product-subtotal" data-title="<?php esc_attr_e('Subtotal', 'woocommerce'); ?>"> <?php echo apply_filters('woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal($_product, $cart_item['quantity']), $cart_item, $cart_item_key); // PHPCS: XSS ok. ?> </td> <!-- Remove Item Column --> <td class="product-remove" data-title="<?php esc_attr_e('操作', 'woocommerce'); ?>"> <?php echo apply_filters('woocommerce_cart_item_remove_link', sprintf( '<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>', esc_url( wc_get_cart_remove_url($cart_item_key) ), esc_attr__('Remove this item', 'woocommerce'), esc_attr($product_id), esc_attr($_product->get_sku()) ), $cart_item_key); ?> </td> </tr> <?php endif; ?> <?php endforeach; ?> <?php do_action('woocommerce_after_cart_contents'); ?> </tbody> </table> <?php do_action('woocommerce_after_cart_table'); ?> </form> </div> <!-- Sticky Footer --> <div class="cart-footer-actions sticky-footer" style="position: sticky; bottom: 0; background: white; padding: 15px; border-top: 1px solid #ddd; max-width: 1200px; margin: 0 auto;"> <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;"> <div class="footer-left"> <input type="checkbox" id="footer-select-all"> <label for="footer-select-all" style="display: inline-block; margin-left: 5px; cursor: pointer;">全选</label> <button type="button" class="button" id="remove-selected-items">刪除選中的商品</button> <button type="button" class="button" id="clear-cart">清空購物車</button> </div> <div class="coupon-section"> <input type="text" name="coupon_code" class="input-text" id="coupon_code" value="" placeholder="输入优惠券代码" style="padding: 8px; width: 200px; border: 1px solid #ddd; border-radius: 4px; margin-right: 5px;" /> <button type="button" class="button" id="apply-coupon">应用优惠券</button> </div> </div> <div style="display: flex; justify-content: space-between; align-items: center;"> <div class="selected-summary" style="font-size: 16px; font-weight: bold;"> 已选商品: <span id="selected-count">0</span> 件,共计: <span id="selected-total">RM0.00</span> </div> <a href="<?php echo esc_url( wc_get_checkout_url() ); ?>" class="checkout-button button alt wc-forward" id="partial-checkout">结算</a> </div> </div> <?php do_action('woocommerce_after_cart'); ?> <style> /* Layout styles (unchanged) */ .cart-page-section { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); margin-bottom: 30px; } .cart-page-section table.cart { width: 100%; border-collapse: collapse; margin-bottom: 20px; } .cart-page-section table.cart th, .cart-page-section table.cart td { padding: 15px; text-align: left; border-bottom: 1px solid #eee; } .cart-page-section table.cart th { background-color: #f8f8f8; font-weight: bold; } .cart-page-section table.cart th.product-select, .cart-page-section table.cart td.product-select { width: 8%; text-align: center; vertical-align: middle; white-space: nowrap; } .cart-page-section table.cart td.product-info { width: 37%; vertical-align: top; } .cart-page-section table.cart .product-info .product-image { float: left; margin-right: 15px; width: 100px; height: 100px; } .cart-page-section table.cart .product-info .product-image img { max-width: 100%; height: auto; display: block; } .cart-page-section table.cart .product-info .product-name { overflow: hidden; } .cart-page-section table.cart td.product-price, .cart-page-section table.cart td.product-quantity, .cart-page-section table.cart td.product-subtotal { width: 15%; vertical-align: middle; } .cart-page-section table.cart td.product-remove { width: 5%; text-align: center; vertical-align: middle; } .cart-footer-actions { position: sticky; bottom: 0; background: #fff; padding: 15px; border-top: 1px solid #ddd; box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1); z-index: 1000; display: flex; flex-direction: column; gap: 15px; } .footer-left { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; } .coupon-section { display: flex; align-items: center; gap: 5px; } .selected-summary { font-size: 16px; font-weight: bold; flex: 1; } .cart-footer-actions .button { padding: 10px 20px; background-color: #f44336; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; transition: background-color 0.3s; white-space: nowrap; } .cart-footer-actions .button:hover { background-color: #d32f2f; } #partial-checkout { padding: 12px 24px; background-color: #2196F3; color: white; text-decoration: none; border-radius: 4px; display: inline-block; transition: background-color 0.3s; white-space: nowrap; text-align: center; font-weight: bold; } #partial-checkout:hover { background-color: #0b7dda; } #coupon_code { padding: 8px; width: 200px; border: 1px solid #ddd; border-radius: 4px; transition: border-color 0.3s; } #coupon_code:focus { border-color: #2196F3; outline: none; } /* Responsive (unchanged) */ @media (max-width: 768px) { .cart-page-section table.cart thead { display: none; } .cart-page-section table.cart td { display: block; width: 100% !important; text-align: right; padding: 10px; position: relative; padding-left: 50%; } .cart-page-section table.cart td::before { content: attr(data-title); position: absolute; left: 15px; font-weight: bold; text-align: left; } .cart-page-section table.cart .product-info .product-image { float: none; margin: 0 auto 10px; } .cart-page-section table.cart td.product-select::before { content: "选择"; } .cart-footer-actions { flex-direction: column; align-items: flex-start; } .footer-left { width: 100%; justify-content: space-between; } .coupon-section { width: 100%; margin-top: 10px; } .coupon-section input { flex: 1; } .cart-footer-actions .footer-bottom-row { flex-direction: column; align-items: stretch; } .selected-summary { text-align: center; margin-bottom: 10px; } #partial-checkout { width: 100%; padding: 15px; } .cart-footer-actions .button { padding: 12px 15px; margin: 5px 0; width: 100%; text-align: center; } } @media (max-width: 480px) { .cart-page-section { padding: 15px; } .cart-page-section table.cart td { padding-left: 45%; } .cart-page-section table.cart td::before { font-size: 14px; } .cart-footer-actions { padding: 10px; } #coupon_code { width: 100%; } } /* Loader overlay above quantity input */ .product-quantity .quantity { position: relative; /* anchor for overlay */ } .quantity-saving-overlay { position: absolute; top: 0; left: 0; right: 0; height: 100%; display: none; /* hidden by default */ align-items: flex-start; /* appear at top */ justify-content: center;/* centered horizontally */ padding-top: 2px; background: rgba(255,255,255,0.0); /* transparent so it doesn't dim UI */ z-index: 10; pointer-events: none; /* don't block typing/clicks when visible */ } .quantity-saving-loader { width: 20px; height: 20px; border: 3px solid #f3f3f3; border-top: 3px solid #3498db; border-radius: 50%; animation: spin 0.8s linear infinite; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } </style> <script> jQuery(function($){ // Context var PC = { ajax_url: (window.wc_cart_params && window.wc_cart_params.ajax_url) || '<?php echo esc_url( admin_url("admin-ajax.php") ); ?>', security: (function(){ var n = $('input[name="woocommerce-cart-nonce"]').val(); if (n) return n; if (window.wc_cart_params && window.wc_cart_params.cart_nonce) return window.wc_cart_params.cart_nonce; return '<?php echo wp_create_nonce("woocommerce-cart"); ?>'; })(), cart_is_empty: <?php echo $pc_cart_is_empty ? 'true' : 'false'; ?>, cart_uid: '<?php echo esc_js($pc_uid); ?>' }; // Keys function lsKey(name){ return 'pc_' + name + '_' + PC.cart_uid; } var LS_SELECTION = lsKey('selected_items'); var LS_MASTER = lsKey('cart_master'); // Utilities function getSelectedKeys(){ return $('.item-checkbox:checked').map(function(){ return this.value; }).get(); } function fmtRM(n){ n = isNaN(n) ? 0 : n; return 'RM' + Number(n).toFixed(2); } // Selection persistence function readSelection(){ try { return JSON.parse(localStorage.getItem(LS_SELECTION) || '[]'); } catch(e){ return []; } } function writeSelection(keys){ try { localStorage.setItem(LS_SELECTION, JSON.stringify(keys||[])); } catch(e){} } function restoreSelectionFromLS(){ var saved = readSelection(); if (!Array.isArray(saved)) saved = []; $('.item-checkbox').each(function(){ $(this).prop('checked', saved.indexOf(this.value) !== -1); }); } window.addEventListener('storage', function(ev){ if (ev.key === LS_SELECTION) { restoreSelectionFromLS(); updateSelectedSummary(); } }); // Selected summary function updateSelectedSummary(){ var total = 0, count = 0; $('.item-checkbox:checked').each(function(){ var price = parseFloat($(this).data('price')); if (!isNaN(price)) { total += price; count++; } }); $('#selected-count').text(count); $('#selected-total').text(fmtRM(total)); var totalCbs = $('.item-checkbox').length; var checkedCbs = $('.item-checkbox:checked').length; var allChecked = totalCbs > 0 && checkedCbs === totalCbs; $('#select-all-items, #footer-select-all').prop('checked', allChecked); writeSelection(getSelectedKeys()); } // Select all $('#select-all-items, #footer-select-all').off('change.sc').on('change.sc', function(){ var checked = $(this).prop('checked'); $('.item-checkbox').prop('checked', checked); updateSelectedSummary(); }); // 单个勾选项变化时,更新统计与“全选”状态 $(document).on('change', '.item-checkbox', updateSelectedSummary); // Snapshot cart DOM -> localStorage (guest resilience) function snapshotCartFromDOM() { var items = []; $('tr.cart_item').each(function(){ var $row = $(this); var pid = parseInt($row.attr('data-product_id'),10)||0; var vid = parseInt($row.attr('data-variation_id'),10)||0; var qty = parseFloat($row.find('input.qty').val())||0; var variation = {}; try { variation = JSON.parse($row.attr('data-variation')||'{}'); } catch(e){ variation = {}; } if (pid && qty > 0) { items.push({ product_id: pid, variation_id: vid, variation: variation, quantity: qty }); } }); try { localStorage.setItem(LS_MASTER, JSON.stringify({ ts: Date.now(), items: items })); } catch(e){} } function maybeRehydrateFromLocal() { if (!PC.cart_is_empty) return; var raw = localStorage.getItem(LS_MASTER); if (!raw) return; var data; try { data = JSON.parse(raw); } catch(e){ return; } var items = (data && data.items) ? data.items : []; if (!items.length) return; $.ajax({ url: PC.ajax_url, method: 'POST', dataType: 'json', data: { action: 'pc_rehydrate_cart', security: PC.security, items: JSON.stringify(items) } }).done(function(res){ if (res && res.success) { location.reload(); // display rehydrated items } }); } // AFTER $('#remove-selected-items').off('click.sc').on('click.sc', function(){ var keys = getSelectedKeys(); if (!keys.length) { alert('请选择要删除的商品'); return; } if (!confirm('确定要删除选中的商品吗?')) return; $.ajax({ url: PC.ajax_url, method: 'POST', dataType: 'json', data: { action: 'remove_selected_cart_items', selected_items: keys, security: PC.security } }).done(function(res){ if (res && res.success) { keys.forEach(function(k){ var $row = $('tr.cart_item[data-cart_item_key="'+k+'"]'); $row.fadeOut(250, function(){ $(this).remove(); snapshotCartFromDOM(); updateSelectedSummary(); }); }); // 从本地选择集合中剔除已删除项 var saved = readSelection().filter(function(k0){ return keys.indexOf(k0) === -1; }); writeSelection(saved); } else { alert((res && res.data && (res.data.message || res.data)) || '删除失败,请重试'); } }).fail(function(){ alert('删除失败,请重试'); }); }); // Clear cart // AFTER $('#clear-cart').off('click.sc').on('click.sc', function(){ if (!confirm('确定要清空购物车吗?')) return; $.ajax({ url: PC.ajax_url, method: 'POST', dataType: 'json', data: { action: 'empty_cart', security: PC.security } }).done(function(res){ if (res && res.success) { writeSelection([]); localStorage.removeItem(LS_MASTER); location.reload(); } else { alert((res && res.data && (res.data.message || res.data)) || '清空购物车失败,请重试'); } }).fail(function(){ alert('清空购物车失败,请重试'); }); }); // Apply coupon // AFTER $('#apply-coupon').off('click.sc').on('click.sc', function(){ var code = ($.trim($('#coupon_code').val()) || ''); if (!code) { alert('请输入优惠券代码'); return; } var $btn = $(this).prop('disabled', true).text('处理中...'); $.ajax({ url: PC.ajax_url, method: 'POST', dataType: 'json', data: { action: 'apply_coupon', coupon_code: code, security: PC.security } }).done(function(res){ if (res && res.success) { location.reload(); } else { alert((res && res.data && (res.data.message || res.data)) || '优惠券应用失败,请重试'); $btn.prop('disabled', false).text('应用优惠券'); } }).fail(function(){ alert('发生错误,请重试'); $btn.prop('disabled', false).text('应用优惠券'); }); }); // ---- Quantity auto-save (fixed regex + loader above input) ---- // 已修正:正确的正则表达式 function parseCartKeyFromInputName(n) { var m = (n || '').match(/^cart\[([a-zA-Z0-9_]+)\]\[qty\]$/); return m ? m[1] : null; } function ensureLoader($quantityContainer){ var $overlay = $quantityContainer.find('.quantity-saving-overlay'); if (!$overlay.length) { $overlay = $('<div class="quantity-saving-overlay"><div class="quantity-saving-loader"></div></div>'); $quantityContainer.append($overlay); } return $overlay; } var qtyTimers = {}; $(document).on('input change', 'input.qty', function(){ var $input = $(this); var key = parseCartKeyFromInputName($input.attr('name')); if (!key) return; var $row = $input.closest('tr.cart_item'); var $quantityContainer = $input.closest('.quantity'); var val = parseInt($input.val(), 10); if (isNaN(val) || val < 0) val = 0; // debounce if (qtyTimers[key]) clearTimeout(qtyTimers[key]); var $overlay = ensureLoader($quantityContainer); $overlay.hide(); qtyTimers[key] = setTimeout(function(){ $overlay.show(); $input.prop('disabled', true); $.ajax({ url: PC.ajax_url, method: 'POST', dataType: 'json', data: { action: 'update_cart_item_qty', cart_item_key: key, qty: val, security: PC.security } }).done(function(res){ if (res && res.success && res.data){ if (res.data.subtotal_html) { $row.find('td.product-subtotal').html(res.data.subtotal_html); } var $cb = $row.find('.item-checkbox'); if ($cb.length && typeof res.data.line_total_incl_tax === 'number') { $cb.attr('data-price', res.data.line_total_incl_tax); } if (val === 0 || res.data.removed) { $row.fadeOut(300, function(){ $(this).remove(); snapshotCartFromDOM(); updateSelectedSummary(); }); } else { snapshotCartFromDOM(); updateSelectedSummary(); } } else { var msg = (res && res.data && (res.data.message || res.data)) || '数量更新失败'; alert(msg); } }).fail(function(){ alert('数量更新失败,请重试'); }).always(function(){ $overlay.hide(); $input.prop('disabled', false); }); }, 500); // 0.5s debounce }); // Partial checkout -> regular checkout page $('#partial-checkout').off('click.sc').on('click.sc', function(e){ e.preventDefault(); var keys = getSelectedKeys(); if (!keys.length) { alert('请至少选择一件商品结算'); return; } var $btn = $(this), t = $btn.text(); $btn.prop('disabled', true).text('创建订单中...'); snapshotCartFromDOM(); $.ajax({ url: PC.ajax_url, method: 'POST', dataType: 'json', data: { action: 'create_direct_order', selected_items: keys, security: PC.security } }).done(function(res){ if (res && res.success && res.data && res.data.checkout_url) { window.location.href = res.data.checkout_url; // /checkout/?pc_token=... } else { alert((res && res.data && (res.data.message || res.data)) || '创建订单失败,请重试'); $btn.prop('disabled', false).text(t); } }).fail(function(xhr){ var msg = '创建订单失败'; if (xhr && xhr.responseJSON && xhr.responseJSON.data) { msg += ':' + (xhr.responseJSON.data.message || xhr.responseJSON.data); } alert(msg); $btn.prop('disabled', false).text(t); }); }); // Keep LS selection after clicking "x" remove; also snapshot $(document).on('click', 'a.remove', function(){ var key = $(this).closest('tr.cart_item').attr('data-cart_item_key'); if (key) { var saved = readSelection().filter(function(k){ return k !== key; }); writeSelection(saved); snapshotCartFromDOM(); } }); // Init restoreSelectionFromLS(); updateSelectedSummary(); snapshotCartFromDOM(); maybeRehydrateFromLocal(); }); // NEW: Real-time cart count updater function updateHeaderCartCount() { $.ajax({ url: PC.ajax_url, method: 'POST', data: { action: 'get_cart_count', security: PC.security }, success: function(response) { if (response.success) { $('.cart-count').text(response.count); } } }); } // Update on cart changes $(document).on('cart_updated', function() { updateHeaderCartCount(); }); // Initial update updateHeaderCartCount(); }); </script> functions.php <?php defined('ABSPATH') || exit; /** * Robust partial checkout to regular /checkout/ with durable cart snapshot * - Snapshot full cart before virtualizing selection for checkout * - Do not remove anything until order is created * - On success (thank-you), rebuild cart as (snapshot - purchased) * - On cancel/back (visit cart), restore snapshot * - Guest resilience: localStorage + rehydrate AJAX */ /* ------------------------------------------------- * Helpers * ------------------------------------------------- */ /** * 新增:购物车数量AJAX端点 */ add_action('wp_ajax_get_cart_count', 'pc_get_cart_count'); add_action('wp_ajax_nopriv_get_cart_count', 'pc_get_cart_count'); function pc_get_cart_count() { check_ajax_referer('woocommerce-cart', 'security'); $count = WC()->cart->get_cart_contents_count(); wp_send_json_success(array('count' => $count)); } function pc_get_cart_uid() { if (is_user_logged_in()) { return 'user_' . get_current_user_id(); } if (empty($_COOKIE['pc_cart_uid'])) { $token = wp_generate_uuid4(); setcookie('pc_cart_uid', $token, time() + YEAR_IN_SECONDS, COOKIEPATH ?: '/', '', is_ssl(), false); $_COOKIE['pc_cart_uid'] = $token; } return 'guest_' . sanitize_text_field(wp_unslash($_COOKIE['pc_cart_uid'])); } function pc_build_item_key($product_id, $variation_id = 0) { return (int)$product_id . '|' . (int)$variation_id; } function pc_snapshot_current_cart() { if (!WC()->cart) wc_load_cart(); $items = array(); foreach (WC()->cart->get_cart() as $ci_key => $ci) { $pid = isset($ci['product_id']) ? (int)$ci['product_id'] : 0; $vid = isset($ci['variation_id']) ? (int)$ci['variation_id'] : 0; $qty = isset($ci['quantity']) ? wc_stock_amount($ci['quantity']) : 0; $var = isset($ci['variation']) && is_array($ci['variation']) ? $ci['variation'] : array(); if ($pid && $qty > 0) { $items[] = array( 'product_id' => $pid, 'variation_id' => $vid, 'variation' => array_map('wc_clean', $var), 'quantity' => $qty, ); } } return $items; } function pc_restore_cart_from_items($items) { if (!WC()->cart) wc_load_cart(); WC()->cart->empty_cart(); foreach ((array)$items as $it) { $pid = isset($it['product_id']) ? (int)$it['product_id'] : 0; $vid = isset($it['variation_id']) ? (int)$it['variation_id'] : 0; $qty = isset($it['quantity']) ? wc_stock_amount($it['quantity']) : 0; $var = isset($it['variation']) && is_array($it['variation']) ? array_map('wc_clean', $it['variation']) : array(); if ($pid && $qty > 0) { WC()->cart->add_to_cart($pid, $qty, $vid, $var); } } WC()->cart->calculate_totals(); } // Fix cart restoration logic add_action('wp_loaded', function() { if (!method_exists(WC()->session, 'get')) return; $token = WC()->session->get('pc_partial_token'); if ($token && WC()->cart->is_empty()) { $payload = get_transient(pc_transient_key($token)); if (!empty($payload['snapshot'])) { pc_restore_cart_from_items($payload['snapshot']); WC()->cart->calculate_totals(); } } }, 20); function pc_transient_key($token) { return 'pc_partial_payload_' . sanitize_key($token); } /* ------------------------------------------------- * AJAX: Local rehydrate when Woo cart is empty * ------------------------------------------------- */ add_action('wp_ajax_pc_rehydrate_cart', 'pc_rehydrate_cart'); add_action('wp_ajax_nopriv_pc_rehydrate_cart', 'pc_rehydrate_cart'); function pc_rehydrate_cart() { check_ajax_referer('woocommerce-cart', 'security'); $raw = isset($_POST['items']) ? wp_unslash($_POST['items']) : ''; $items = is_string($raw) ? json_decode($raw, true) : (array)$raw; if (!is_array($items)) { wp_send_json_error(array('message' => 'Invalid items.'), 400); } if (!WC()->cart) wc_load_cart(); if (!WC()->cart->is_empty()) { wp_send_json_success(array('message' => 'Cart not empty.')); } foreach ($items as $it) { $pid = isset($it['product_id']) ? (int)$it['product_id'] : 0; $vid = isset($it['variation_id']) ? (int)$it['variation_id'] : 0; $qty = isset($it['quantity']) ? wc_stock_amount($it['quantity']) : 0; $var = isset($it['variation']) && is_array($it['variation']) ? array_map('wc_clean', $it['variation']) : array(); if ($pid && $qty > 0) { WC()->cart->add_to_cart($pid, $qty, $vid, $var); } } WC()->cart->calculate_totals(); wp_send_json_success(array('rehydrated' => true)); } /* ------------------------------------------------- * AJAX: Update qty (per-row; no page reload) * ------------------------------------------------- */ add_action('wp_ajax_update_cart_item_qty', 'pc_update_cart_item_qty'); add_action('wp_ajax_nopriv_update_cart_item_qty', 'pc_update_cart_item_qty'); function pc_update_cart_item_qty() { check_ajax_referer('woocommerce-cart', 'security'); $key = isset($_POST['cart_item_key']) ? wc_clean(wp_unslash($_POST['cart_item_key'])) : ''; $qty = isset($_POST['qty']) ? wc_stock_amount($_POST['qty']) : null; if (!$key || $qty === null) { wp_send_json_error(array('message' => 'Missing params.'), 400); } if (!WC()->cart) wc_load_cart(); if ($qty <= 0) { $removed = WC()->cart->remove_cart_item($key); WC()->cart->calculate_totals(); wp_send_json_success(array('removed' => (bool)$removed)); } else { $set = WC()->cart->set_quantity($key, $qty, true); WC()->cart->calculate_totals(); $cart_item = WC()->cart->get_cart_item($key); if (!$cart_item) { wp_send_json_error(array('message' => 'Cart item not found after update.'), 404); } $_product = $cart_item['data']; $subtotal_html = apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal($_product, $cart_item['quantity']), $cart_item, $key ); // Use line_total + line_tax (after totals) for checkbox data-price $line_total_incl_tax = (float)($cart_item['line_total'] + $cart_item['line_tax']); wp_send_json_success(array( 'subtotal_html' => $subtotal_html, 'line_total_incl_tax' => $line_total_incl_tax, 'removed' => false, )); } } /* ------------------------------------------------- * AJAX: Remove selected * ------------------------------------------------- */ add_action('wp_ajax_remove_selected_cart_items', 'pc_remove_selected_cart_items'); add_action('wp_ajax_nopriv_remove_selected_cart_items', 'pc_remove_selected_cart_items'); function pc_remove_selected_cart_items() { check_ajax_referer('woocommerce-cart', 'security'); $keys = isset($_POST['selected_items']) ? (array) $_POST['selected_items'] : array(); if (!WC()->cart) wc_load_cart(); foreach ($keys as $k) { $k = wc_clean(wp_unslash($k)); WC()->cart->remove_cart_item($k); } WC()->cart->calculate_totals(); wp_send_json_success(true); } /* ------------------------------------------------- * AJAX: Empty cart * ------------------------------------------------- */ add_action('wp_ajax_empty_cart', 'pc_empty_cart'); add_action('wp_ajax_nopriv_empty_cart', 'pc_empty_cart'); function pc_empty_cart() { check_ajax_referer('woocommerce-cart', 'security'); if (!WC()->cart) wc_load_cart(); WC()->cart->empty_cart(); wp_send_json_success(true); } /* ------------------------------------------------- * AJAX: Apply coupon * ------------------------------------------------- */ add_action('wp_ajax_apply_coupon', 'pc_apply_coupon'); add_action('wp_ajax_nopriv_apply_coupon', 'pc_apply_coupon'); function pc_apply_coupon() { check_ajax_referer('woocommerce-cart', 'security'); $code = isset($_POST['coupon_code']) ? wc_format_coupon_code(wp_unslash($_POST['coupon_code'])) : ''; if (!$code) { wp_send_json_error(array('message' => __('请输入优惠券代码', 'woocommerce')), 400); } if (!WC()->cart) wc_load_cart(); $applied = WC()->cart->apply_coupon($code); WC()->cart->calculate_totals(); if (is_wp_error($applied)) { wp_send_json_error(array('message' => $applied->get_error_message()), 400); } if (!$applied) { wp_send_json_error(array('message' => __('优惠券应用失败', 'woocommerce')), 400); } wp_send_json_success(true); } /* ------------------------------------------------- * AJAX: Start partial checkout to regular checkout page * ------------------------------------------------- */ add_action('wp_ajax_create_direct_order', 'pc_create_direct_order'); add_action('wp_ajax_nopriv_create_direct_order', 'pc_create_direct_order'); function pc_create_direct_order() { check_ajax_referer('woocommerce-cart', 'security'); $selected_keys = isset($_POST['selected_items']) ? (array) $_POST['selected_items'] : array(); if (empty($selected_keys)) { wp_send_json_error(array('message' => __('请选择要结算的商品', 'woocommerce')), 400); } if (!WC()->cart) wc_load_cart(); // Snapshot full cart $snapshot = pc_snapshot_current_cart(); // Build selected items from current cart based on cart_item_key list $selected = array(); foreach (WC()->cart->get_cart() as $ci_key => $ci) { if (!in_array($ci_key, $selected_keys, true)) { continue; } $pid = (int)$ci['product_id']; $vid = (int)$ci['variation_id']; $qty = wc_stock_amount($ci['quantity']); $var = isset($ci['variation']) && is_array($ci['variation']) ? array_map('wc_clean', $ci['variation']) : array(); if ($pid && $qty > 0) { $selected[] = array( 'product_id' => $pid, 'variation_id' => $vid, 'variation' => $var, 'quantity' => $qty, ); } } if (empty($selected)) { wp_send_json_error(array('message' => __('没有可结算的商品', 'woocommerce')), 400); } $token = wp_generate_uuid4(); $payload = array( 'uid' => pc_get_cart_uid(), 'snapshot' => $snapshot, 'selected' => $selected, 'created' => time(), ); set_transient(pc_transient_key($token), $payload, 2 * DAY_IN_SECONDS); // Put token in session (used across checkout AJAX calls) if (method_exists(WC()->session, 'set')) { WC()->session->set('pc_partial_token', $token); } $checkout_url = add_query_arg('pc_token', rawurlencode($token), wc_get_checkout_url()); wp_send_json_success(array('checkout_url' => $checkout_url)); } /* ------------------------------------------------- * Virtualize cart on checkout for token and rebuild after purchase * ------------------------------------------------- */ // Entering checkout with token: virtualize cart to selected items add_action('woocommerce_before_checkout_form', function() { if (!isset($_GET['pc_token'])) return; $token = sanitize_text_field(wp_unslash($_GET['pc_token'])); $payload = get_transient(pc_transient_key($token)); if (empty($payload) || empty($payload['selected'])) return; if (!WC()->cart) wc_load_cart(); // Virtualize to selected items only pc_restore_cart_from_items($payload['selected']); // Persist token in session for all subsequent checkout AJAX calls if (method_exists(WC()->session, 'set')) { WC()->session->set('pc_partial_token', $token); } }, 1); // Safety: just-in-time re-virtualization before order processing add_action('woocommerce_before_checkout_process', function() { if (!method_exists(WC()->session, 'get')) return; $token = WC()->session->get('pc_partial_token'); if (!$token) return; $payload = get_transient(pc_transient_key($token)); if (empty($payload) || empty($payload['selected'])) return; // Ensure cart still equals selected set pc_restore_cart_from_items($payload['selected']); }, 1); // Tag order with token add_action('woocommerce_checkout_create_order', function($order) { $token = null; if (isset($_GET['pc_token'])) { $token = sanitize_text_field(wp_unslash($_GET['pc_token'])); } elseif (method_exists(WC()->session, 'get')) { $token = WC()->session->get('pc_partial_token'); } if ($token) { $order->update_meta_data('_pc_partial_token', $token); $order->update_meta_data('_pc_cart_snapshot', $token); } }, 10, 1); // Fixed: Only remove purchased items from cart add_action('woocommerce_thankyou', function($order_id) { $order = wc_get_order($order_id); if (!$order) return; $token = $order->get_meta('_pc_partial_token'); if (!$token) return; $payload = get_transient(pc_transient_key($token)); if (empty($payload) || empty($payload['snapshot'])) { if (method_exists(WC()->session, 'set')) { WC()->session->set('pc_partial_token', null); } delete_transient(pc_transient_key($token)); return; } // 1. Restore FULL snapshot (all items) pc_restore_cart_from_items($payload['snapshot']); WC()->cart->calculate_totals(); // 2. Remove only the purchased (selected) items foreach ($payload['selected'] as $selected_item) { $cart_item_key = pc_find_cart_item($selected_item['product_id'], $selected_item['variation_id']); if ($cart_item_key) { WC()->cart->remove_cart_item($cart_item_key); } } // 3. Update cart totals WC()->cart->calculate_totals(); // Cleanup token if (method_exists(WC()->session, 'set')) { WC()->session->set('pc_partial_token', null); } delete_transient(pc_transient_key($token)); }, 20); // Helper: Find cart item by product and variation ID function pc_find_cart_item($product_id, $variation_id = 0) { if (!WC()->cart) wc_load_cart(); foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { $cart_pid = isset($cart_item['product_id']) ? (int)$cart_item['product_id'] : 0; $cart_vid = isset($cart_item['variation_id']) ? (int)$cart_item['variation_id'] : 0; if ($cart_pid == $product_id && $cart_vid == $variation_id) { return $cart_item_key; } } return false; } // Visiting cart with active token: restore full snapshot (cancel/back) add_action('woocommerce_before_cart', function() { if (!method_exists(WC()->session, 'get')) return; $token = WC()->session->get('pc_partial_token'); if (!$token) return; $payload = get_transient(pc_transient_key($token)); if (empty($payload) || empty($payload['snapshot'])) return; // Restore full snapshot so cart page always shows everything pc_restore_cart_from_items($payload['snapshot']); }, 1); /* ------------------------------------------------- * Keep cart count accurate during checkout process * ------------------------------------------------- */ add_filter('woocommerce_cart_contents_count', function($count) { // Check if partial token exists if (!method_exists(WC()->session, 'get')) return $count; $token = WC()->session->get('pc_partial_token'); if ($token) { $payload = get_transient(pc_transient_key($token)); // Always show full cart count even during checkout if (!empty($payload['snapshot'])) { $snapshot_count = 0; foreach ($payload['snapshot'] as $item) { $snapshot_count += (int)$item['quantity']; } return $snapshot_count; } } return $count; }); // Ensure cart item totals are accurate in header add_action('woocommerce_before_cart', function() { pc_maintain_cart_consistency(); }); add_action('woocommerce_before_checkout_form', function() { pc_maintain_cart_consistency(); }); function pc_maintain_cart_consistency() { if (!method_exists(WC()->session, 'get')) return; $token = WC()->session->get('pc_partial_token'); if (!$token) return; $payload = get_transient(pc_transient_key($token)); if (empty($payload) || empty($payload['snapshot'])) return; // Immediately restore full cart for consistent UI pc_restore_cart_from_items($payload['snapshot']); WC()->cart->calculate_totals(); }
最新发布
09-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jarry.liu

如果对您有帮助,鼓励下博主吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值