Commit d5d6f1f5 by Jaxon

Merge branch 'feature/marketing-sop-push-strategy' into 'SAAS+V5.8.3'

Feature/marketing sop push strategy

See merge request !757
2 parents 7533bb77 405ef10b
Showing 39 changed files with 3404 additions and 178 deletions
{
"mcpServers": {
"codegraph": {
"type": "stdio",
"command": "codegraph",
"args": [
"serve",
"--mcp"
]
}
}
}
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"vetur.validation.template": false, "vetur.validation.template": false,
"vetur.validation.script": false, "vetur.validation.script": false,
"vetur.validation.style": true, "vetur.validation.style": true,
"vetur.useWorkspaceDependencies": true,
"vetur.ignoreProjectWarning": false, "vetur.ignoreProjectWarning": false,
"vetur.experimental.templateInterpolationService": false, "vetur.experimental.templateInterpolationService": false,
"editor.defaultFormatter": "dbaeumer.vscode-eslint", "editor.defaultFormatter": "dbaeumer.vscode-eslint",
......
...@@ -6,37 +6,53 @@ ENV DEBIAN_FRONTEND=noninteractive ...@@ -6,37 +6,53 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
curl \ curl \
git \ git \
nano \ nano \
ca-certificates \ ca-certificates \
bash \ bash \
unzip \ unzip \
jq \ jq \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# 创建用户(uid=1000)
RUN useradd -m -u 1000 -s /bin/bash claude
# 切换到 claude 用户
USER claude
ENV HOME=/home/claude
# Volta # Volta
ENV VOLTA_HOME=/root/.volta ENV VOLTA_HOME=/home/claude/.volta
ENV PATH=$VOLTA_HOME/bin:$PATH ENV PATH=${VOLTA_HOME}/bin:${PATH}
# 安装 Volta
RUN curl https://get.volta.sh | bash RUN curl https://get.volta.sh | bash
# 安装 Node
# 安装 Node14
RUN volta install node@14 RUN volta install node@14
# 默认 Node22
RUN volta install node@22 RUN volta install node@22
# 安装 Claude Code
# Claude Code
RUN npm install -g @anthropic-ai/claude-code RUN npm install -g @anthropic-ai/claude-code
# 触发一次 claude 命令让它生成初始的 ~/.claude.json(如果它还没生成的话) # 初始化 Claude 配置
# 并使用 jq 安全地注入 hasCompletedOnboarding 字段,不破坏原有内容 RUN mkdir -p /home/claude/.claude && \
RUN mkdir -p /root && \ echo '{}' > /home/claude/.claude.json && \
touch /root/.claude.json && \ jq '. + {"hasCompletedOnboarding": true}' \
(echo '{}' > /root/.claude.json) && \ /home/claude/.claude.json \
jq '. + {"hasCompletedOnboarding": true}' /root/.claude.json > /root/.claude.json.tmp && \ > /home/claude/.claude.json.tmp && \
mv /root/.claude.json.tmp /root/.claude.json mv /home/claude/.claude.json.tmp /home/claude/.claude.json
# ==========================
# 最后统一修正权限
# ==========================
USER root
RUN chown -R 1000:1000 /home/claude
# 恢复默认运行用户
USER claude
WORKDIR /workspace WORKDIR /workspace
CMD ["/bin/bash"] CMD ["/bin/bash"]
services: services:
ai-worker: ai-worker:
# user: "1000:1000"
build: build:
context: . context: .
dockerfile: ../build/Dockerfile.unit.test dockerfile: ../build/Dockerfile.unit.test
container_name: ai-worker container_name: ai-worker
working_dir: /workspace working_dir: /workspace
volumes: volumes:
- ./workspace:/workspace - npm-cache:/home/jdkapp/.npm
# npm 缓存
- npm-cache:/home/claude/.npm
# Claude 登录状态
- claude-cache:/home/claude/.claude/projects
# Volta 缓存(node、npm)
- volta-cache:/home/claude/.volta
environment: environment:
- ANTHROPIC_AUTH_TOKEN - ANTHROPIC_AUTH_TOKEN
- GIT_AUTHOR_NAME=AI-BOT
- GIT_AUTHOR_EMAIL=ai-bot@didihu.com.cn
- GIT_COMMITTER_NAME=AI-BOT
- GIT_COMMITTER_EMAIL=ai-bot@didihu.com.cn
- AI_GITLAB_TOKEN
- ANTHROPIC_BASE_URL=https://dashscope.aliyuncs.com/apps/anthropic - ANTHROPIC_BASE_URL=https://dashscope.aliyuncs.com/apps/anthropic
- ANTHROPIC_MODEL=qwen3.5-plus - ANTHROPIC_MODEL=qwen3.5-plus
- ANTHROPIC_SMALL_FAST_MODEL=qwen3.5-flash - ANTHROPIC_SMALL_FAST_MODEL=qwen3.5-flash
...@@ -17,6 +29,15 @@ services: ...@@ -17,6 +29,15 @@ services:
- ANTHROPIC_DEFAULT_SONNET_MODEL=qwen3.5-plus - ANTHROPIC_DEFAULT_SONNET_MODEL=qwen3.5-plus
- ANTHROPIC_DEFAULT_OPUS_MODEL=qwen3.5-plus - ANTHROPIC_DEFAULT_OPUS_MODEL=qwen3.5-plus
- CLAUDE_CODE_SUBAGENT_MODEL=qwen3.5-plus - CLAUDE_CODE_SUBAGENT_MODEL=qwen3.5-plus
# 保持容器在前台常驻,防止执行完立刻退出崩溃
command: sh -c "tail -f /dev/null" command: >
sh -c '
git config --global credential.helper store &&
echo "http://oauth2:$${AI_GITLAB_TOKEN}@gitlab.test.glsx.com.cn" > ~/.git-credentials &&
tail -f /dev/null
'
restart: unless-stopped restart: unless-stopped
volumes:
npm-cache:
claude-cache:
volta-cache:
...@@ -21,7 +21,9 @@ function request( ...@@ -21,7 +21,9 @@ function request(
) { ) {
// 兼容线上dj和scrm appkey和secret不一样的情况 // 兼容线上dj和scrm appkey和secret不一样的情况
let apiName = ""; let apiName = "";
if (params.method.includes("dj.api.smartcarlife")) { if (params.method.includes("dj.api.smartcarlife.sop.strategy")) {
apiName = "strategy";
} else if (params.method.includes("dj.api.smartcarlife")) {
apiName = "dj"; apiName = "dj";
} else if (params.method.includes("dj.api.script")) { } else if (params.method.includes("dj.api.script")) {
apiName = "script"; apiName = "script";
......
...@@ -2,19 +2,19 @@ ...@@ -2,19 +2,19 @@
* 时间控件-限制月份 * 时间控件-限制月份
*/ */
export const beforeRangePickerOptions = { export const beforeRangePickerOptions = {
disabledDate(date) { disabledDate(date) {
if (date > new Date()) { if (date > new Date()) {
return true return true;
} }
return false return false;
} },
} };
export const afterRangePickerOptions = { export const afterRangePickerOptions = {
disabledDate(date) { disabledDate(date) {
const yesterday = new Date(new Date().setDate(new Date().getDate() - 1)) const yesterday = new Date(new Date().setDate(new Date().getDate() - 1));
if (date < yesterday) { if (date < yesterday) {
return true return true;
} }
return false return false;
} },
} };
<template> <template>
<el-dialog ref="elDialog" <el-dialog ref="elDialog"
v-bind="$attrs" v-bind="$attrs"
:visible.sync="innerVisible" :custom-class="dialogCustomClass"
:width="computedWidth" :fullscreen="innerFullscreen"
:fullscreen="innerFullscreen" :show-close="false"
:custom-class="dialogCustomClass" :visible.sync="innerVisible"
:show-close="false" :width="computedWidth"
v-on="$listeners" v-on="$listeners"
@open="handleOpen"> @open="handleOpen">
<!-- Title slot wrapper for fullscreen support --> <!-- Title slot wrapper for fullscreen support -->
<template #title> <template #title>
<div class="venus-dialog-header-inner"> <div class="venus-dialog-header-inner">
<slot name="title"> <slot name="title">
<span class="el-dialog__title">{{ $attrs.title }}</span> <span class="el-dialog__title">{{ $attrs.title }}</span>
</slot> </slot>
<div class="venus-dialog-actions"> <div class="venus-dialog-actions">
<!-- Fullscreen toggle button --> <!-- Fullscreen toggle button -->
<button v-if="allowFullscreen" <button v-if="allowFullscreen"
type="button" class="venus-dialog-action-btn"
class="venus-dialog-action-btn" type="button"
@click="toggleFullscreen"> @click="toggleFullscreen">
<i :class="innerFullscreen ? 'el-icon-crop' : 'el-icon-full-screen'"></i> <i :class="innerFullscreen ? 'el-icon-crop' : 'el-icon-full-screen'"></i>
</button> </button>
<!-- Custom Close button --> <!-- Custom Close button -->
<button v-if="showClose" <button v-if="showClose"
type="button" class="venus-dialog-action-btn"
class="venus-dialog-action-btn" type="button"
@click="handleClose"> @click="handleClose">
<i class="el-icon-close"></i> <i class="el-icon-close"></i>
</button> </button>
</div> </div>
</div>
</template>
<!-- Default slot for dialog body -->
<slot></slot>
<!-- Footer slot -->
<template #footer>
<transition name="footer-slide">
<div v-if="showFooter" class="venus-dialog-footer-wrapper">
<slot name="footer">
<div class="venus-dialog-footer">
<VenusButton v-if="showCancel"
size="small"
@click="handleCancel">
{{ cancelText }}
</VenusButton>
<VenusButton size="small"
type="primary"
:loading="confirmLoading"
@click="handleConfirm">
{{ confirmText }}
</VenusButton>
</div> </div>
</template> </slot>
</div>
<!-- Default slot for dialog body --> </transition>
<slot></slot> </template>
</el-dialog>
<!-- Footer slot -->
<template #footer>
<transition name="footer-slide">
<div v-if="showFooter" class="venus-dialog-footer-wrapper">
<slot name="footer">
<div class="venus-dialog-footer">
<VenusButton v-if="showCancel"
size="small"
@click="handleCancel">
{{ cancelText }}
</VenusButton>
<VenusButton size="small"
type="primary"
:loading="confirmLoading"
@click="handleConfirm">
{{ confirmText }}
</VenusButton>
</div>
</slot>
</div>
</transition>
</template>
</el-dialog>
</template> </template>
<script> <script>
......
/**
* @param {Array} arr 原数组
* @param {number} fromIndex 原下标
* @param {number} toIndex 目标下标
* @returns {Array} 新数组,不修改原数组
*/
export function moveItem(arr, fromIndex, toIndex) {
if (fromIndex === toIndex)
return [...arr];
// 先拷贝一份新数组
const newArr = [...arr];
// 取出并删除原位置元素
const item = newArr.splice(fromIndex, 1)[0];
// 插入到目标位置
newArr.splice(toIndex, 0, item);
return newArr;
}
...@@ -10,3 +10,17 @@ export function readFileAsDataURL(file) { ...@@ -10,3 +10,17 @@ export function readFileAsDataURL(file) {
}; };
}); });
} }
const IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "gif", "webp", "bmp", "svg", "ico"];
/**
* 根据文件后缀判断是否为图片
* @param {string} fileName - 文件名
* @returns {boolean}
*/
export function isImageFile(fileName) {
if (!fileName || typeof fileName !== "string")
return false;
const ext = fileName.split(".").pop()?.toLowerCase();
return IMAGE_EXTENSIONS.includes(ext);
}
...@@ -123,4 +123,72 @@ export const routerName = { ...@@ -123,4 +123,72 @@ export const routerName = {
}, },
], ],
}, },
92210: {
path: "/marketing-push-strategy",
name: "marketingPushStrategy",
meta: {
title: "营销推送策略",
authId: "92210",
parentId: "922",
cache: false,
},
component: _import("marketingManagement/marketingPushStrategy/views/table/index"),
auth: [
{
authId: "9221001",
parentId: "92210",
label: "新增策略",
category: "Button",
type: "primary",
handle: "handleModify",
addRoutePath: [
{
authId: "9221010",
name: "新增策略",
parentId: "92210",
},
],
},
{
authId: "9221002",
parentId: "92210",
label: "执行记录",
handle: "handleRecord",
},
{
authId: "9221003",
parentId: "92210",
label: "修改",
handle: "handleModify",
addRoutePath: [
{
authId: "9221010",
name: "修改策略",
parentId: "92210",
},
],
},
{
authId: "9221004",
parentId: "92210",
label: "删除",
handle: "handleDelete",
},
],
},
9221010: {
path: "/marketing-push-strategy/modify",
name: "marketingPushStrategyModify",
meta: {
title: "新增策略",
authId: "9221010",
parentId: "92210",
cache: false,
sideHidden: true,
activePath: "/marketing-push-strategy/modify",
},
component: _import("marketingManagement/marketingPushStrategy/views/modify/index"),
},
}; };
<!-- 关联门店弹窗 --> <!-- 关联门店弹窗 -->
<template> <template>
<d2-dialog btn-ok-label="确定" <d2-dialog btn-ok-label="确定"
class="relateStore" class="relateStore"
:is-visible.sync="relateStoreVisible" width="70%"
:title="title" :is-visible.sync="relateStoreVisible"
width="70%" :title="title"
@closeDialog="handleRelateStoreClose" @closeDialog="handleRelateStoreClose"
@confirmDialog="handleRelateStoreConfirm"> @confirmDialog="handleRelateStoreConfirm">
<slot /> <slot />
<el-row class="tableCon"> <el-row class="tableCon">
<div class="tableBox left"> <div class="tableBox left">
<el-table ref="seletingTable" <el-table ref="seletingTable"
border class="table"
class="table" height="464px"
:data="selectingData" border
height="464px" :data="selectingData"
@select="handleChange" @select="handleChange"
@select-all="handleAll"> @select-all="handleAll">
<el-table-column align="center" <el-table-column align="center"
type="selection" type="selection"
width="55" /> width="55" />
<el-table-column align="center" <template v-for="(item, index) in tablecolumnList">
label="门店名称" <el-table-column v-if="tableHeadItems.includes(item.label)"
prop="merchantName"> :key="index"
</el-table-column> align="center"
<el-table-column align="center" :label="item.label"
label="门店地址" :prop="item.prop">
prop="merchantAddress"> </el-table-column>
</el-table-column> </template>
<el-table-column align="center" </el-table>
label="门店商户号" <el-pagination layout="total, prev, pager, next"
prop="merchantId"> background
</el-table-column> small
<el-table-column align="center" :current-page.sync="currentPage"
label="服务对接" :page-size="pageSize"
prop="yqMerchantName"> :total="total"
</el-table-column> @current-change="handleCurrentChange" />
<el-table-column align="center" </div>
label="服务对接商户号" <el-table class="tableBox table"
prop="yqMerchantId"> height="464px"
</el-table-column> border
</el-table> :data="selectedData">
<el-pagination background <el-table-column align="center"
:current-page.sync="currentPage" label="门店名称"
layout="total, prev, pager, next" prop="merchantName">
:page-size="pageSize" <template #default="scope">
small <span>{{ scope.row.merchantName }}</span>
:total="total" </template>
@current-change="handleCurrentChange" /> </el-table-column>
</div> <el-table-column align="center"
<el-table border label="门店商户号"
class="tableBox table" prop="merchantId">
:data="selectedData" <template #default="scope">
height="464px"> <span>{{ scope.row.merchantId }}</span>
<el-table-column align="center" </template>
label="门店名称" </el-table-column>
prop="merchantName"> <el-table-column align="center"
<template #default="scope"> label="删除"
<span>{{ scope.row.merchantName }}</span> width="50px">
</template> <template #default="scope">
</el-table-column> <el-button class="el-icon-delete"
<el-table-column align="center" type="text"
label="门店商户号" @click="handleDelete(scope.row)" />
prop="merchantId"> </template>
<template #default="scope"> </el-table-column>
<span>{{ scope.row.merchantId }}</span> </el-table>
</template> </el-row>
</el-table-column> </d2-dialog>
<el-table-column align="center"
label="删除"
width="50px">
<template #default="scope">
<el-button class="el-icon-delete"
type="text"
@click="handleDelete(scope.row)" />
</template>
</el-table-column>
</el-table>
</el-row>
</d2-dialog>
</template> </template>
<script> <script>
...@@ -114,11 +102,42 @@ export default { ...@@ -114,11 +102,42 @@ export default {
default: false, default: false,
}, },
selectedSceneType: { selectedSceneType: {
type: String type: String,
} },
page: {
type: String,
default: "",
},
tableHeadItems: {
type: Array,
default: () => {
return this.tablecolumnList.map(item => item.label);
},
},
}, },
data() { data() {
return { return {
tablecolumnList: [{
label: "门店名称",
prop: "merchantName",
align: "center",
}, {
label: "门店地址",
prop: "merchantAddress",
align: "center",
}, {
label: "门店商户号",
prop: "merchantId",
align: "center",
}, {
label: "服务对接",
prop: "yqMerchantName",
align: "center",
}, {
label: "服务对接商户号",
prop: "yqMerchantId",
align: "center",
}],
selectedData: [], selectedData: [],
selectingData: [], selectingData: [],
// 分页 // 分页
...@@ -147,7 +166,7 @@ export default { ...@@ -147,7 +166,7 @@ export default {
currentPage: this.currentPage, currentPage: this.currentPage,
pageSize: this.pageSize, pageSize: this.pageSize,
baseSceneCode: this.selectedBaseSceneCode, baseSceneCode: this.selectedBaseSceneCode,
queryMerchantAddr: true queryMerchantAddr: true,
}).then((res) => { }).then((res) => {
res?.list?.forEach((val) => { res?.list?.forEach((val) => {
// 账户中心门店返回商户号字段是merchantNo // 账户中心门店返回商户号字段是merchantNo
......
import request from "@api/request";
import RequestMethods from "@/api/request.methods";
const path = "dj.api.smartcarlife.sop.strategy.";
// 查询策略列表
export function getList(data) {
data.method = `${path}list`;
return request(data);
}
// 查询策略详情
export function getMarketingPushStrategyDetailApi(data) {
data.method = `${path}query`;
return request(data, "post");
}
// 创建策略
export function createStrategy(data) {
data.method = `${path}create`;
return request(data, "post");
}
// 修改策略
export function updateStrategy(data) {
data.method = `${path}update`;
return request(data, "post");
}
// 启停策略
export function statusStrategy(data) {
data.method = `${path}status`;
return request(data, "post");
}
// 删除策略
export function deleteStrategy(data) {
data.method = `${path}delete`;
return request(data, "post");
}
// 策略任务确认(支持批量)
export function confirmStrategy(data) {
data.method = `${path}confirm`;
return request(data, "post");
}
// 查询策略执行记录列表
export function recordsStrategy(data) {
data.method = `${path}records`;
return request(data, "post");
}
// 查询策略执行详情(含快照)
export function recordDetail(data) {
data.method = `${path}record.detail`;
return request(data, "post");
}
// 元数据查询接口
export function getMetaData(data) {
data.method = `${path}meta`;
return request(data, "post");
}
export function getMetaOptionsApi(data = {}) {
data.method = "dj.api.smartcarlife.sop.strategy.meta";
return request(data, RequestMethods.POST);
}
<template>
<RelateStoreDialog v-if="relateStoreVisible"
ref="formRelateStore"
page="marketingPushStrategy"
title="选择门店"
:relate-store-visible="relateStoreVisible"
:store-api="getMerchantList"
:store-search-form="storeSearchForm"
:store-selected="storeSelected"
:table-head-items="tableHeadItems"
@handleRelateStoreClose="handleRelateStoreClose"
@handleRelateStoreConfirm="handleRelateStoreConfirm">
<template #default>
<el-row>
<el-form ref="relate"
:inline="true"
:model="storeSearchForm">
<el-form-item label="门店名称:">
<el-input v-model.trim="storeSearchForm.merchantName"
placeholder="门店名称"
clearable
@keydown.native="handleStoreInput" />
</el-form-item>
<el-form-item label="门店商户号:">
<el-input v-model.trim="storeSearchForm.merchantId"
placeholder="门店商户号"
clearable
@keydown.native="handleStoreInput" />
</el-form-item>
<el-button type="primary" @click="handleSearchStore">
搜索
</el-button>
</el-form>
</el-row>
</template>
</RelateStoreDialog>
</template>
<script>
import { getMerchantList } from "@/api/merchant";
import relateStoreDialog from "@/views/goods/grounding/components/relateStoreDialog.vue";
export default {
components: {
RelateStoreDialog: relateStoreDialog,
},
props: {
relateStoreVisible: {
type: Boolean,
default: false,
},
storeSelected: {
type: Array,
default: () => [],
},
},
data() {
return {
getMerchantList,
storeSearchForm: {
merchantName: "",
merchantId: "",
yqMerchantName: "",
yqMerchantId: "",
},
tableHeadItems: ["门店名称", "门店地址", "门店商户号"],
};
},
mounted() { },
methods: {
handleStoreInput(e) {
e.keyCode === 13 && this.handleSearchStore();
},
// 门店搜索
handleSearchStore() {
this.$refs.formRelateStore.handleCurrentChange(1);
},
handleRelateStoreConfirm(selectedData) {
if (!selectedData.length) {
this.$message({
message: "请选择门店",
type: "warning",
showClose: true,
});
return true;
}
// this.formData.merchantGoodsRefList = selectedData;
// // 清空产品信息
// this.clearUpgradeGoods();
// this.relateStoreVisible = false;
this.$emit("handleRelateStoreConfirm", selectedData);
},
handleRelateStoreClose() {
this.$emit("handleRelateStoreClose");
},
},
};
</script>
<style scoped>
</style>
<template>
<div class="actions-item-wrapper">
<div class="title-wrapper">
<div class="title">
{{ title }}
</div>
<el-button class="del-button"
icon="el-icon-delete"
size="small"
type="danger"
plain
@click="handleRemoveActions">
删除动作
</el-button>
</div>
<el-form-item label="动作类型:"
:prop="`${propPrefix}.actionType`"
:rules="[{ required: true, message: '请选择动作类型', trigger: 'change' }]">
<el-select style="width:530px"
:value="item.actionType"
@change="handleActionTypeChange">
<el-option label="向客户群发送消息"
:value="1">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="目标群:"
:prop="`${propPrefix}.targetGroupType`"
:rules="[{ required: true, message: '请选择目标群', trigger: 'change' }]">
<el-radio-group :value="item.targetGroupType">
<el-radio :label="1">
目标客户所在群
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="消息内容:"
style="margin-bottom:0 "
:prop="`${propPrefix}.messageType`"
:rules="[
{ required: true, message: '请选择消息类型', trigger: 'change' },
{ validator: validateMessageType, trigger: 'blur' },
]">
<MessageType :item="item"
:message-variables="options.messageVariables"
@input="handleMessageTypeChange" />
</el-form-item>
</div>
</template>
<script>
import MessageType from "@/views/marketingManagement/marketingPushStrategy/components/messageType";
import { MessageTypeEnum } from "@/views/marketingManagement/marketingPushStrategy/constant";
export default {
name: "",
components: {
MessageType,
},
props: {
propPrefix: {
type: String,
default: "",
},
title: {
type: String,
default: "动作",
},
// options.triggers = [] 动作触发条件
// options.messageVariables = [] 消息变量选项
options: {
type: Object,
default: () => ({}),
},
item: {
type: Object,
required: true,
},
},
data() {
return {
tempSelect: undefined,
tempRadio: 1,
temp: {
messageType: 1,
},
};
},
computed: {
},
mounted() {
},
methods: {
validateMessageType(rule, value, callback) {
if (!String(this.item.messageType)) {
callback(new Error("请选择消息类型"));
}
if (this.item.messageType === MessageTypeEnum.VARIABLE_TEXT) {
if (!this.item.content) {
callback(new Error("请输入消息内容"));
}
}
if (this.item.messageType === MessageTypeEnum.VARIABLE_IMAGE) {
if (!this.item.medias) {
callback(new Error("请上传消息图片"));
}
if (!this.item.medias.length) {
callback(new Error("请上传消息图片"));
}
}
if (this.item.messageType === MessageTypeEnum.VARIABLE_VIDEO) {
if (!this.item.medias) {
callback(new Error("请上传消息视频"));
}
if (!this.item.medias.length) {
callback(new Error("请上传消息视频"));
}
}
if (this.item.messageType === MessageTypeEnum.VARIABLE_WEBPAGE) {
if (!this.item.pageTitle || !this.item.pageDesc || !this.item.bgColor) {
callback(new Error("请编辑网页内容"));
}
if (!this.item.materialJson) {
callback(new Error("网页内容的素材不可为空"));
}
if (!this.item.materialJson.length) {
callback(new Error("网页内容的素材不可为空"));
}
if (!String(this.item.intervalPx)) {
callback(new Error("请编辑网页内容"));
}
}
callback();
},
handleActionTypeChange(e) {
this.$emit("input", { ...this.item, actionType: e });
},
handleMessageTypeChange(e) {
this.$emit("input", e);
},
handleRemoveActions() {
this.$emit("remove");
},
},
};
</script>
<style scoped lang="scss">
.actions-item-wrapper {
border-radius: 8px;
border: 1px solid #e5e5e5;
padding: 16px 16px;
> .title-wrapper {
font-style: Bold;
font-size: 14px;
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
> .title {
line-height: 16px;
}
.del-button {
border-style: dashed;
background: white;
transition: background-color 200ms;
&:hover {
background: #fef0f0;
color: #f56c6c;
}
}
}
}
</style>
<template>
<div class="branch-group-wrapper">
<BranchItem v-for="(branch, index) in list"
:key="branch._key"
:branch="branch"
:options="{
messageVariables,
triggers,
conditionVariables,
}"
:prop-prefix="`${propPrefix}[${index}]`"
:title="`分支${index + 1}`"
@appendAction="handleAppendAction(index)"
@input="handleBranchChange($event, index)"
@removeAction="handleRemoveAction($event, index)"
@removeBranch="handleRemoveBranch(index)"
@update:conditionGroups="handleBranchConditionChange($event, index)" />
<el-button class="append-btn"
block
@click="handleAppendBranch">
<i class="el-icon-plus "></i>
添加分支
</el-button>
</div>
</template>
<script>
import BranchItem from "@/views/marketingManagement/marketingPushStrategy/components/branchItem/index.vue";
import { getDefaultAction, getDefaultBranch } from "@/views/marketingManagement/marketingPushStrategy/constant";
export default {
name: "",
components: {
BranchItem,
},
model: {
prop: "list",
event: "input",
},
props: {
propPrefix: {
type: String,
default: "",
},
list: {
type: Array,
default: () => ([]),
},
messageVariables: {
type: Array,
default: () => ([]),
},
conditionVariables: {
type: Array,
default: () => ([]),
},
triggers: {
type: Array,
default: () => ([]),
},
},
data() {
return {
};
},
computed: {
},
mounted() {
},
methods: {
handleBranchConditionChange({ conditionGroups }, branchIndex) {
const newList = JSON.parse(JSON.stringify(this.list));
newList[branchIndex].conditionGroups = conditionGroups;
this.$emit("input", newList);
},
handleRemoveAction(actionIndex, branchIndex) {
const newList = JSON.parse(JSON.stringify(this.list));
newList[branchIndex].actions.splice(actionIndex, 1);
this.$emit("input", newList);
},
handleAppendBranch() {
const newList = JSON.parse(JSON.stringify(this.list));
console.log(newList.length);
newList.push(getDefaultBranch(newList.length));
this.$emit("input", newList);
},
handleRemoveBranch(branchIndex) {
const newList = JSON.parse(JSON.stringify(this.list));
newList.splice(branchIndex, 1);
this.$emit("input", newList);
},
handleAppendAction(branchIndex) {
const newList = JSON.parse(JSON.stringify(this.list));
newList[branchIndex].actions.push(getDefaultAction());
this.$emit("input", newList);
},
handleBranchChange({ actionIndex, actionItem }, branchIndex) {
const newList = JSON.parse(JSON.stringify(this.list));
newList[branchIndex].actions[actionIndex] = actionItem;
this.$emit("input", newList);
},
},
};
</script>
<style scoped lang="scss">
.branch-group-wrapper {
.branch-item-wrapper {
margin-top: 20px;
&:first-child {
margin-top: 0;
}
}
.append-btn {
width: 100%;
margin-top: 20px;
}
}
</style>
<template>
<div class="branch-item-wrapper">
<div class="title-wrapper">
<span class="title">{{ title }}</span>
<el-button class="del-button"
icon="el-icon-delete"
size="small"
type="danger"
plain
@click="handleRemoveBranch">
删除分支
</el-button>
</div>
<div class="container-wrapper">
<el-form-item label="满足条件时执行:"
label-width="150px"
required
:prop="`${propPrefix}.conditionGroups`"
:rules="[{ required: true, message: '请选择条件组', trigger: 'change', type: 'array', min: 1 }]">
<ConditionPanel :condition-variables-options="options.conditionVariables"
:list="branch.conditionGroups"
@change="handleBranchConditionChange"
@input="handleBranchConditionInput" />
</el-form-item>
<div class="tips">
按顺序执行以下动作
</div>
<div class="actions-list-wrapper">
<Actions v-for="(action, index) in branch.actions"
:key="action._key"
:item="action"
:options="options"
:prop-prefix="`${propPrefix}.actions[${index}]`"
:title="`动作${index + 1}`"
@input="handleActionChange($event, index)"
@remove="handleRemoveActions(index)" />
<div class="actions-list-foot-wrapper">
<el-button @click="handleAppendAction">
添加动作
</el-button>
</div>
</div>
</div>
</div>
</template>
<script>
import Actions from "@/views/marketingManagement/marketingPushStrategy/components/actionsItem/index.vue";
import ConditionPanel from "@/views/marketingManagement/marketingPushStrategy/components/conditionPanel/index.vue";
export default {
name: "",
components: {
Actions,
ConditionPanel,
},
inject: ["elForm"],
props: {
propPrefix: {
type: String,
default: "",
},
title: {
type: String,
default: "条件组",
},
// options.triggers 动作触发条件
// options.messageVariables 消息变量选项
// options.conditionVariables 条件变量选项
options: {
type: Object,
default: () => ({}),
},
branch: {
type: Object,
required: true,
},
},
data() {
return {
conditionList: [],
};
},
computed: {
},
mounted() {
},
methods: {
handleBranchConditionChange() {
this.elForm?.validateField(`${this.propPrefix}.conditionGroups`);
},
handleRemoveBranch() {
this.$emit("removeBranch");
},
handleAppendAction() {
this.$emit("appendAction");
},
handleRemoveActions(actionIndex) {
this.$emit("removeAction", actionIndex);
},
handleActionChange(e, actionIndex) {
this.$emit("input", { actionItem: e, actionIndex });
},
handleBranchConditionInput(e) {
this.$emit("update:conditionGroups", { conditionGroups: e });
},
},
};
</script>
<style scoped lang="scss">
.branch-item-wrapper {
border-radius: 8px;
overflow: hidden;
border: 1px solid #0000001a;
> .title-wrapper {
padding: 10px 16px;
font-style: Bold;
font-size: 14px;
display: flex;
align-items: center;
justify-content: space-between;
background-color: #f5f6fa;
> .title {
line-height: 16px;
}
.del-button {
border-style: dashed;
background: white;
transition: background-color 200ms;
&:hover {
background: #fef0f0;
color: #f56c6c;
}
}
}
> .container-wrapper {
padding: 20px;
> .tips {
font-weight: 700;
font-style: Bold;
font-size: 14px;
color: #333;
line-height: 16px;
}
.actions-list-wrapper {
margin-top: 20px;
.actions-item-wrapper {
margin-top: 20px;
&:first-child {
margin-top: 0;
}
}
}
.actions-list-foot-wrapper {
margin-top: 20px;
}
}
}
</style>
<template>
<div class="condition-container-wrapper">
<el-form-item label-width="0"
:prop="`${propPrefix}.variableCode`"
:rules="[
{ required: true, message: '请选择变量', trigger: 'change' },
]">
<el-select placeholder="请选择变量"
style="width:212px"
:value="item.variableCode"
@change="handleVariableChange">
<el-option v-for="opt in options.conditionVariables"
:key="opt.variableCode"
:label="opt.variableName"
:value="opt.variableCode">
</el-option>
</el-select>
</el-form-item>
<el-form-item label-width="0"
:prop="`${propPrefix}.operator`"
:rules="[
{ required: true, message: '请选择操作符', trigger: 'change' },
]">
<el-select placeholder="请选择操作符"
style="width:160px"
:disabled="!item.variableCode"
:value="item.operator"
@change="handleOperatorChange">
<el-option v-for="opt in getOperatorOptions "
:key="opt.code"
:label="opt.name"
:value="opt.code">
</el-option>
</el-select>
</el-form-item>
<el-form-item label-width="0" :prop="`${propPrefix}.valueSource`">
<el-radio-group style="width:98px"
:value="item.valueSource"
@input="handleValueSource">
<el-radio-button :label="enums.conditionVariableSourceTypeEnum.VARIABLE">
变量
</el-radio-button>
<el-radio-button :label="enums.conditionVariableSourceTypeEnum.VALUE">
值
</el-radio-button>
</el-radio-group>
</el-form-item>
<template v-if="item.valueSource === enums.conditionVariableSourceTypeEnum.VARIABLE">
<el-form-item label-width="0"
:prop="`${propPrefix}.variableRefCode`"
:rules="[
{ required: true, message: '请选择变量', trigger: 'change' },
]">
<el-select placeholder="请选择"
style="width:212px"
:disabled="!item.variableCode"
:value="item.variableRefCode"
@change="handleVariableRefCodeChange">
<el-option v-for="opt in getVariableRefCodeOptions"
:key="opt.variableCode"
:label="opt.variableName"
:value="opt.variableCode">
</el-option>
</el-select>
</el-form-item>
</template>
<template v-if="item.valueSource === enums.conditionVariableSourceTypeEnum.VALUE">
<!-- 默认 -->
<el-form-item v-if="![
enums.conditionVariableTypeEnum.TEXT,
enums.conditionVariableTypeEnum.NUMBER,
enums.conditionVariableTypeEnum.DATE,
enums.conditionVariableTypeEnum.ENUM,
].includes(getCurrentVariable.variableType)"
label-width="0">
<el-input placeholder="请先选择变量"
style="width:212px"
disabled>
</el-input>
</el-form-item>
<!-- 文字类型 -->
<el-form-item v-if="getCurrentVariable.variableType === enums.conditionVariableTypeEnum.TEXT"
label-width="0"
:prop="`${propPrefix}.textValue`"
:rules="[
{ required: true, message: '请输入文字值', trigger: 'change' },
]">
<el-input style="width:212px"
:value="item.textValue"
@input="handleTextInput">
</el-input>
</el-form-item>
<!-- 数字类型 -->
<el-form-item v-if="getCurrentVariable.variableType === enums.conditionVariableTypeEnum.NUMBER"
label-width="0"
:prop="`${propPrefix}.numberValue`"
:rules="[
{ required: true, message: '请输入数值', trigger: 'change' },
]">
<el-input-number placeholder="请输入数值"
style="width:212px;"
:controls="false"
:value="item.numberValue"
@change="handleNumberChange">
</el-input-number>
</el-form-item>
<!-- 日期类型 -->
<el-form-item v-if="getCurrentVariable.variableType === enums.conditionVariableTypeEnum.DATE"
label-width="0"
:prop="`${propPrefix}.dateValue`"
:rules="[
{ required: true, message: '请选择日期', trigger: 'change' },
]">
<el-date-picker placeholder="请选择日期"
style="width:212px"
type="date"
value-format="yyyy-MM-DD"
:value="item.dateValue"
@input="handleDateChange">
</el-date-picker>
</el-form-item>
<!-- 枚举类型 -->
<el-form-item v-if="getCurrentVariable.variableType === enums.conditionVariableTypeEnum.ENUM"
label-width="0"
:prop="`${propPrefix}.enumValue`"
:rules="[
{ required: true, message: '请选择枚举值', trigger: 'change' },
]">
<el-select placeholder="请先选择枚举值"
style="width:212px"
:value="item.enumValue"
@change="handleEnumChange">
<el-option v-for="opt in getVariableEnumOptions"
:key="opt.enumCode"
:label="opt.enumName"
:value="opt.enumCode">
</el-option>
</el-select>
</el-form-item>
</template>
<el-form-item label-width="0">
<el-button class="del-button"
type="text"
@click="handleRemove">
删除
</el-button>
</el-form-item>
</div>
</template>
<script>
import { ConditionVariableSourceTypeEnum, ConditionVariableTypeEnum } from "@/views/marketingManagement/marketingPushStrategy/constant/index.js";
export default {
name: "",
model: {
prop: "item",
event: "input",
},
props: {
propPrefix: {
type: String,
default: "",
},
options: {
type: Object,
default: () => ({
conditionVariables: [],
}),
},
item: {
type: Object,
required: true,
},
},
data() {
return {
enums: {
conditionVariableSourceTypeEnum: ConditionVariableSourceTypeEnum,
conditionVariableTypeEnum: ConditionVariableTypeEnum,
},
};
},
computed: {
getCurrentVariable() {
const variable = this.options.conditionVariables.find(item => item.variableCode === this.item.variableCode);
return variable || {};
},
getOperatorOptions() {
if (!this.item.variableCode) {
return [];
}
return this.getCurrentVariable?.operators || [];
},
getVariableRefCodeOptions() {
if (!this.item.variableCode) {
return [];
}
return this.getCurrentVariable?.sopConditionVariableDTOList || [];
},
getVariableEnumOptions() {
if (!this.item.variableCode) {
return [];
}
return this.getCurrentVariable?.enumValues || [];
},
},
mounted() {
},
methods: {
handleRemove() {
this.$emit("remove");
},
updateItem(key, val) {
this.$emit("input", { ...this.item, [key]: val });
},
handleVariableChange(val) {
// 只要切换一个, 子级全清
// variableType
const variable = this.options.conditionVariables.find(item => item.variableCode === val);
this.$emit("input", {
...this.item,
variableCode: val,
variableType: variable?.variableType,
operator: undefined,
valueSource: 0,
variableRefCode: undefined,
textValue: undefined,
numberValue: undefined,
enumValue: undefined,
dateValue: undefined,
});
},
handleOperatorChange(val) {
this.updateItem("operator", val);
},
handleValueSource(val) {
// 切换, 清子级
// variableType
this.$emit("input", {
...this.item,
valueSource: val,
variableRefCode: undefined,
textValue: undefined,
numberValue: undefined,
enumValue: undefined,
dateValue: undefined,
});
},
handleVariableRefCodeChange(val) {
this.updateItem("variableRefCode", val);
},
handleTextInput(val) {
this.updateItem("textValue", val);
},
handleNumberChange(val) {
this.updateItem("numberValue", val);
},
handleDateChange(val) {
this.updateItem("dateValue", val);
},
handleEnumChange(val) {
this.updateItem("enumValue", val);
},
},
};
</script>
<style scoped lang="scss">
.condition-container-wrapper {
display: flex;
align-items: center;
flex: 1 0 0;
overflow: hidden;
> .el-form-item {
flex-shrink: 0;
flex-basis: 0;
margin-right: 8px;
::v-deep .el-input-number {
.el-input__inner {
text-align: left;
}
}
}
.del-button {
transition: color 200ms;
&:hover {
color: #f56c6c;
}
}
}
</style>
import { nanoid } from "nanoid";
export function getDefaultConditionGroup() {
return {
_key: nanoid(),
conditions: [
getDefaultCondition(),
],
};
}
export function getDefaultCondition() {
return {
_key: nanoid(),
valueSource: 0,
};
}
<template>
<div class="condition-group-wrapper">
<el-form ref="ConditionFormRef"
class="condition-form-wrapper"
size="small"
:hide-required-asterisk="false"
:model="formModel">
<template v-for="(item, index) in list">
<div :key="item._key" class="condition-item">
<el-divider v-if="index !== 0" class="divider-wrapper">
<div class="divider-content">
或
</div>
</el-divider>
<ConditionItem :conditions="list[index].conditions"
:options="options"
:prop-prefix="`list[${index}]`"
:title="`条件组${index + 1}`"
@appendCondition="handleAppendCondition(index)"
@input="handleUpdate(index, $event)"
@removeCondition="handleRemoveCondition($event, index)"
@removeConditionGroup="handleRemoveConditionGroup(index)" />
</div>
</template>
<div class="footer-wrapper">
<el-button class="append-button"
icon="el-icon-plus"
@click="handleAppendConditionGroup">
添加条件组
</el-button>
</div>
</el-form>
</div>
</template>
<script>
import ConditionItem from "@/views/marketingManagement/marketingPushStrategy/components/conditionItem/index.vue";
import { getDefaultCondition, getDefaultConditionGroup } from "./constant";
export default {
name: "",
components: {
ConditionItem,
},
model: {
prop: "list",
event: "input",
},
props: {
list: {
type: Array,
default: () => [getDefaultConditionGroup()],
},
// options.conditionVariables
options: {
type: Object,
default: () => ({}),
},
},
computed: {
formModel() {
return { list: this.list };
},
},
mounted() {
this.$refs.ConditionFormRef?.resetFields();
},
methods: {
handleUpdate(groupIndex, { conditionItem, conditionIndex }) {
const newList = this.list.map(group => ({
...group,
conditions: [...group.conditions],
}));
newList[groupIndex].conditions[conditionIndex] = conditionItem;
this.$emit("input", newList);
},
handleAppendConditionGroup() {
this.$emit("input", [...this.list, getDefaultConditionGroup()]);
},
handleRemoveConditionGroup(groupIndex) {
this.$emit("input", this.list.filter((_, i) => i !== groupIndex));
},
handleAppendCondition(groupIndex) {
const newList = this.list.map(group => ({
...group,
conditions: [...group.conditions],
}));
newList[groupIndex].conditions.push(getDefaultCondition());
this.$emit("input", newList);
},
handleRemoveCondition({ conditionIndex }, groupIndex) {
const newList = this.list.map(group => ({
...group,
conditions: [...group.conditions],
}));
newList[groupIndex].conditions.splice(conditionIndex, 1);
this.$emit("input", newList);
},
},
};
</script>
<style scoped lang="scss">
.condition-group-wrapper {
width: 100%;
overflow: hidden;
}
.condition-form-wrapper {
::v-deep .el-form-item {
margin-bottom: 14px;
&.action-form-item {
margin-bottom: 0;
}
}
.footer-wrapper {
text-align: center;
.append-button {
border-style: dashed;
width: 100%;
line-height: 40px;
padding-top: 0;
padding-bottom: 0;
border-radius: 4px;
margin-top: 20px;
}
}
.condition-item {
margin-top: 12px;
&:first-child {
margin-top: 0;
}
}
.divider-wrapper {
background-color: #e5e5e5;
margin: 26px 0;
::v-deep .el-divider__text {
padding: 0 8px;
}
.divider-content {
border-radius: 20px;
padding: 0px 16px;
font-size: 14px;
line-height: 24px;
background-color: #f5f7fa;
color: #2a58ad;
}
}
}
</style>
<template>
<div class="condition-wrapper">
<div class="title-wrapper">
<span class="title">{{ title }}</span>
<el-button class="del-button"
icon="el-icon-delete"
size="small"
type="danger"
plain
@click="handleRemoveGroup">
删除条件组
</el-button>
</div>
<div class="condition-container-list">
<div v-for="(item, index) in conditions"
:key="item._key"
class="condition-item">
<el-divider v-if="index !== 0" class="divider-wrapper">
<div class="divider-content">
且
</div>
</el-divider>
<div class="condition-row">
<div class="title">
条件{{ index + 1 }}
</div>
<ConditionContainer :item="conditions[index]"
:options="options"
:prop-prefix="`${propPrefix}.conditions[${index}]`"
@input="handleUpdateCondition($event, index)"
@remove="handleRemoveCondition(index)">
</ConditionContainer>
</div>
</div>
</div>
<div class="foot-wrapper">
<el-form-item class="action-form-item" label-width="0">
<el-button class="append-btn"
icon="el-icon-plus"
size="small"
@click="handleAppendCondition">
添加条件
</el-button>
</el-form-item>
</div>
</div>
</template>
<script>
import ConditionContainer from "@/views/marketingManagement/marketingPushStrategy/components/conditionContainer/index.vue";
export default {
name: "ConditionItem",
components: {
ConditionContainer,
},
model: {
prop: "conditions",
event: "input",
},
props: {
options: {
type: Object,
default: () => ({}),
},
propPrefix: {
type: String,
default: "",
},
conditions: {
type: Array,
required: true,
},
title: {
type: String,
default: "条件组",
},
},
methods: {
handleUpdateCondition(conditionItem, index) {
console.log("?");
this.$emit("input", { conditionItem, conditionIndex: index });
},
handleAppendCondition() {
this.$emit("appendCondition");
},
handleRemoveCondition(index) {
this.$emit("removeCondition", { conditionIndex: index });
},
handleRemoveGroup() {
this.$emit("removeConditionGroup");
},
},
};
</script>
<style scoped lang="scss">
.condition-wrapper {
padding: 16px;
border-radius: 4px;
border: 1px solid #e5e5e5;
background: white;
.condition-container-list {
padding-top: 8px;
.condition-item {
width: 100%;
overflow: hidden;
.condition-row {
display: flex;
align-items: center;
width: 100%;
overflow: hidden;
> .title {
font-weight: 400;
font-size: 14px;
margin-right: 8px;
white-space: nowrap;
width: 4em;
margin-bottom: 14px;
}
}
}
}
> .title-wrapper {
display: flex;
align-items: center;
justify-content: space-between;
> .title {
font-style: Bold;
font-size: 14px;
}
.del-button {
border-style: dashed;
background: white;
transition: background-color 200ms;
&:hover {
background: #fef0f0;
color: #f56c6c;
}
}
}
.foot-wrapper {
.append-btn {
border-style: dashed;
border-radius: 4px;
background-color: white;
transition: background-color 200ms;
&:hover {
background-color: #eaeaf7;
}
}
}
.divider-wrapper {
background-color: #e5e5e5;
margin: 10px 0 24px;
::v-deep .el-divider__text {
padding: 0 8px;
}
.divider-content {
border-radius: 20px;
border: 1px solid #e5e5e5;
padding: 0px 8px;
font-size: 14px;
line-height: 24px;
color: #999;
}
}
}
</style>
<template>
<div class="condition-panel-wrapper">
<template v-if="list.length <= 0 ">
<el-button icon="el-icon-plus"
plain
@click="handleShowConditionGroup">
设置条件规则
</el-button>
</template>
<div v-else class="text-panel">
<ConditionTextPanel :condition-list="list" :condition-variables="conditionVariablesOptions" />
<div class="action-wrapper">
<el-button type="text" @click="handleShowConditionGroup">
重新编辑
</el-button>
<el-button class="red-btn"
type="text"
@click="handleClearCondition">
清除
</el-button>
</div>
</div>
<el-drawer custom-class="step2-condition-group-drawer"
size="880px"
title="设置条件规则"
append-to-body
:visible.sync="dialog.step2ConditionGroup.show"
:wrapper-closable="false">
<div class="drawer-content">
<ConditionGroup v-if="dialog.step2ConditionGroup.show"
ref="ConditionGroupRef"
v-model="dialog.step2ConditionGroup.conditionCache"
:options="{ conditionVariables: conditionVariablesOptions }" />
</div>
<div class="footer-wrapper">
<el-button size="small" @click="handleCloseConditionGroup">
取消
</el-button>
<el-button size="small"
type="primary"
@click="handleConfirmConditionGroup">
确认
</el-button>
</div>
</el-drawer>
</div>
</template>
<script>
import { cloneDeep } from "lodash-es";
import { getDefaultConditionGroup } from "@/views/marketingManagement/marketingPushStrategy/components/conditionGroup/constant.js";
import ConditionGroup from "@/views/marketingManagement/marketingPushStrategy/components/conditionGroup/index.vue";
import ConditionTextPanel from "@/views/marketingManagement/marketingPushStrategy/components/conditionTextyPanel/index.vue";
export default {
name: "ConditionPanel",
components: {
ConditionGroup,
ConditionTextPanel,
},
model: {
prop: "list",
event: "input",
},
props: {
conditionVariablesOptions: {
type: Array,
default: () => ([]),
},
list: {
type: Array,
default: () => ([]),
},
},
data() {
return {
dialog: {
step2ConditionGroup: {
show: false,
conditionCache: {},
},
},
};
},
computed: {
},
mounted() {
},
methods: {
handleClearCondition() {
this.$emit("input", []);
this.$emit("change", []);
},
handleShowConditionGroup() {
this.dialog.step2ConditionGroup.show = true;
this.dialog.step2ConditionGroup.conditionCache = cloneDeep(this.list);
if (this.dialog.step2ConditionGroup.conditionCache.length === 0) {
this.dialog.step2ConditionGroup.conditionCache.push(getDefaultConditionGroup());
}
},
handleCloseConditionGroup() {
this.dialog.step2ConditionGroup.show = false;
this.dialog.step2ConditionGroup.conditionCache = [];
},
async handleConfirmConditionGroup() {
const ConditionGroupRef = this.$refs.ConditionGroupRef;
if (!ConditionGroupRef) {
return;
}
const ConditionFormRef = ConditionGroupRef.$refs.ConditionFormRef;
if (!ConditionFormRef) {
return;
}
await ConditionFormRef.validate();
// 校验不通过不会往下执行
const condition = cloneDeep(this.dialog.step2ConditionGroup.conditionCache);
this.$emit("input", condition);
this.$emit("change", condition);
this.handleCloseConditionGroup();
},
},
};
</script>
<style scoped lang="scss">
::v-deep .el-drawer__header {
font-weight: 600;
font-size: 16px;
line-height: 22px;
padding: 20px;
margin-bottom: 0;
border-bottom: 1px solid #e5e5e5;
color: #333;
}
::v-deep .el-drawer__body {
overflow: hidden;
flex-shrink: 0;
flex-basis: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
.drawer-content {
padding: 20px;
width: 100%;
flex: 1 0 0;
overflow-y: auto;
overflow-x: hidden;
position: relative;
box-sizing: border-box;
.condition-group-wrapper {
width: 100%;
overflow: hidden;
}
&::after {
content: "";
display: block;
height: 1px;
}
}
> .footer-wrapper {
width: 100%;
display: flex;
justify-content: flex-end;
padding: 20px;
border-top: 1px solid #e5e5e5;
}
}
.condition-panel-wrapper {
display: inline-block;
max-width: 400px;
overflow-x: auto;
}
.text-panel {
> .action-wrapper {
text-align: right;
.red-btn {
color: #eb4e4e;
transition: color 200ms;
&:hover {
color: #f05a5a;
}
&:active {
color: #c54242;
}
}
}
}
</style>
<template>
<div class="condition-text-panel-wrapper">
<div v-for="(conditionGroup, conditionGroupIndex) in list"
:key="conditionGroup.id || conditionGroup._key"
class="condition-group-text-wrapper">
<div v-for="(condition, conditionIndex) in conditionGroup.conditions"
:key="condition.id || condition._key"
class="condition-item-text-wrapper"
style="margin-left:14px">
<div>
<span>
{{ condition.variableName }}
</span>
<span>
{{ condition.operatorName }}
</span>
<span>
{{ condition.valueLabel }}
</span>
</div>
<div v-if="conditionGroup.conditions.length > 1 && conditionIndex !== conditionGroup.conditions.length - 1"
style="margin-top:4px;margin-bottom:4px;padding-left:8px;color:#999999 ">
且
</div>
</div>
<div v-if="list.length > 1 && conditionGroupIndex !== list.length - 1"
style="margin-left:4px;margin-top:8px;margin-bottom:8px;color:#F59619">
或
</div>
</div>
</div>
</template>
<script>
import { cloneDeep, isArray } from "lodash-es";
import { ConditionVariableSourceTypeEnum, ConditionVariableTypeEnum } from "@/views/marketingManagement/marketingPushStrategy/constant/index.js";
export default {
name: "",
props: {
conditionList: {
type: Array,
default: () => ([]),
},
conditionVariables: {
type: Array,
default: () => ([]),
},
},
data() {
return {
list: [],
};
},
computed: {
},
watch: {
conditionList: {
handler(newVal, oldVal) {
if (!isArray(this.conditionList)) {
return;
}
const list = cloneDeep(this.conditionList);
for (const group of list) {
for (const condition of group.conditions) {
const option = this.conditionVariables.find(item => item.variableCode === condition.variableCode);
console.log("option", option);
const operator = option.operators.find(item => item.code === condition.operator);
if (option) {
condition.variableName = option.variableName;
condition.operatorName = operator.name;
if (condition.valueSource === ConditionVariableSourceTypeEnum.VARIABLE) {
const variableOption = option.sopConditionVariableDTOList.find(item => item.variableCode === condition.variableRefCode);
condition.valueLabel = variableOption?.variableName || "-";
} else {
condition.valueLabel = condition.numberValue ?? (condition.textValue || condition.dateValue || condition.enumValue);
}
}
}
}
this.list = list;
},
immediate: true,
deep: true,
},
},
mounted() {
},
methods: {
},
};
</script>
<style scoped lang="scss">
.red-btn {
color: #eb4e4e;
}
.condition-text-panel-wrapper {
background-color: #f5f7fa;
padding: 16px;
border-radius: 8px;
.condition-group-text-wrapper {
font-size: 12px;
line-height: 14px;
}
}
</style>
<template>
<div class="">
<div>
<el-radio-group :value="item.messageType" @input="handleMessageTypeChange">
<el-radio :label="MessageTypeEnum.VARIABLE_TEXT">
文本
</el-radio>
<el-radio :label="MessageTypeEnum.VARIABLE_IMAGE">
图片
</el-radio>
<el-radio :label="MessageTypeEnum.VARIABLE_VIDEO">
视频
</el-radio>
<el-radio :label="MessageTypeEnum.VARIABLE_WEBPAGE">
网页
</el-radio>
</el-radio-group>
</div>
<div style="margin-top:14px">
<div v-if="item.messageType === MessageTypeEnum.VARIABLE_TEXT" class="type-item">
<VariableTextarea style="width:580px"
:value="item.content"
:variable-list="messageVariables"
@input="handleContentChange" />
</div>
<div v-if="item.messageType === MessageTypeEnum.VARIABLE_IMAGE" class="type-item">
<VenusOssUpload :key="item.messageType"
v-model="fileList"
type="image"
@change="(urls, _currentUrl, _currentName, names, sizes) => handleMediasChange(urls, names, sizes, 1)" />
</div>
<div v-if="item.messageType === MessageTypeEnum.VARIABLE_VIDEO" class="type-item">
<VenusOssUpload :key="item.messageType"
v-model="fileList"
type="video"
:file-size="50"
@change="(urls, _currentUrl, _currentName, names, sizes) => handleMediasChange(urls, names, sizes, 2)" />
</div>
<div v-if="item.messageType === MessageTypeEnum.VARIABLE_WEBPAGE" class="type-item">
<el-button size="mini"
plain
@click="handleShowPageConfig">
编辑
</el-button>
</div>
</div>
<VenusDialog v-model="dialog.page.show"
title="编辑网页内容"
width="1060px"
:close-on-click-modal="false"
@close="handleClosePageConfig"
@confirm="handleConfirmPageConfig">
<PageConfig v-if="dialog.page.show"
ref="PageConfig"
v-model="itemCache" />
</VenusDialog>
</div>
</template>
<script>
import { cloneDeep, last } from "lodash-es";
import VenusDialog from "@/components/venusDialog";
import VenusOssUpload from "@/components/venusOssUpload";
import { MessageTypeEnum } from "@/views/marketingManagement/marketingPushStrategy/constant";
import PageConfig from "../pageConfig/index.vue";
import VariableTextarea from "../variableTextarea";
export default {
name: "",
components: {
VariableTextarea,
VenusOssUpload,
VenusDialog,
PageConfig,
},
model: {
prop: "item",
event: "input",
},
props: {
item: {
type: Object,
required: true,
},
messageVariables: {
type: Array,
default: () => ([]),
},
},
data() {
return {
fileList: [],
itemCache: undefined,
MessageTypeEnum,
dialog: {
page: {
show: false,
},
},
};
},
computed: {
},
watch: {
"item.medias": {
immediate: true,
handler(newVal) {
if (MessageTypeEnum.VARIABLE_IMAGE === this.item.messageType) {
this.fileList = (newVal || []).filter(item => item.mediaType === 1).map(item => item.mediaUrl);
}
if (MessageTypeEnum.VARIABLE_VIDEO === this.item.messageType) {
this.fileList = (newVal || []).filter(item => item.mediaType === 2).map(item => item.mediaUrl);
}
},
},
},
mounted() {
},
methods: {
handleShowPageConfig() {
this.dialog.page.show = true;
this.itemCache = cloneDeep(this.item);
},
handleClosePageConfig() {
this.dialog.page.show = false;
this.itemCache = {};
},
async handleConfirmPageConfig() {
const PageConfigRef = this.$refs.PageConfig;
if (!PageConfigRef) {
return;
}
const pageConfigFormRef = PageConfigRef.$refs.PageConfigFromRef;
if (!pageConfigFormRef) {
return;
}
await pageConfigFormRef.validate();
this.$emit("input", this.itemCache);
await this.$nextTick();
this.handleClosePageConfig();
},
handleMediasChange(urls, names, sizes, mediaType) {
this.$emit("input", { ...this.item, medias: urls.map((item, index) => ({
mediaType,
mediaName: names[index],
mediaUrl: item,
sortNo: index,
})) });
},
handleMessageTypeChange(e) {
this.fileList = [];
this.$emit("input", {
...this.item,
messageType: e,
content: "",
medias: [],
pageTitle: "",
pageDesc: "",
bgColor: "#ffffff",
materialJson: [],
intervalPx: 0,
});
},
handleContentChange(e) {
this.$emit("input", { ...this.item, content: e });
},
handlePageConfigChange(e) {
this.$emit("input", e);
},
},
};
</script>
<style scoped lang="scss">
</style>
const EMPTY_TEXT = "-";
function getValue(value) {
if (value === 0)
return 0;
return value || EMPTY_TEXT;
}
function flattenConditions(conditionGroups) {
if (!Array.isArray(conditionGroups))
return [];
return conditionGroups.reduce((list, group) => {
const conditions = Array.isArray(group.conditions) ? group.conditions : [];
return list.concat(conditions.map(item => item.conditionDesc).filter(Boolean));
}, []);
}
function parseMaterials(materialJson) {
if (!materialJson)
return [];
try {
const list = JSON.parse(materialJson);
if (!Array.isArray(list))
return [];
const typeMap = {
image: "图片",
video: "视频",
};
return list
.filter(item => item && item.url)
.map(item => ({
typeName: typeMap[item.type] || item.type || "素材",
url: item.url,
}));
} catch (e) {
return [];
}
}
export function getBasicRows(info = {}) {
const basicInfo = info.basicInfo || {};
return [
{ label: "策略名称", value: getValue(basicInfo.strategyName) },
{ label: "适用场景", value: getValue(basicInfo.bizTypeName) },
{ label: "适用门店", value: getValue(basicInfo.storeDescription || basicInfo.storeScopeDesc) },
{ label: "营销阶段", value: getValue(basicInfo.marketingStageName) },
];
}
export function getCustomerRows(info = {}) {
const customerInfo = info.customerInfo || {};
return [
{ label: "所属门店", value: getValue(customerInfo.storeName) },
{ label: "客户名称", value: getValue(customerInfo.customerName) },
{ label: "客户手机号", value: getValue(customerInfo.customerPhone) },
];
}
export function getTriggerRows(info = {}) {
const triggerInfo = info.triggerInfo || {};
const rows = [
{ label: "触发类型", value: getValue(triggerInfo.triggerTypeName) },
{ label: "实际触发时间", value: getValue(triggerInfo.triggerTimeDesc) },
];
const conditionText = flattenConditions(triggerInfo.step2ConditionGroups).join(";");
if (conditionText) {
rows.push({ label: "同时满足以下条件", value: conditionText });
}
rows.push({ label: "动作执行确认", value: getValue(triggerInfo.actionConfirmDesc) });
return rows;
}
export function getBranchBlocks(info = {}) {
const branches = Array.isArray(info.branches) ? info.branches : [];
return branches.map((branch, branchIndex) => {
const conditionText = flattenConditions(branch.conditionGroups).join(";") || "默认分支";
const actions = Array.isArray(branch.actions) ? branch.actions : [];
return {
name: branch.branchName || `分支${branchIndex + 1}`,
conditionText,
actions: actions.map((action, actionIndex) => {
const actionTitle = action.actionTypeName === "发送消息" ? "向客户群发送消息" : getValue(action.actionTypeName);
const rows = [
{ label: "动作", value: getValue(action.actionTypeName) },
{ label: "消息类型", value: getValue(action.messageTypeName) },
{ label: "消息内容", value: getValue(action.content) },
];
if (action.bgColor) {
rows.push({ label: "背景颜色", value: action.bgColor });
}
if (action.intervalPx || action.intervalPx === 0) {
rows.push({ label: "素材间距", value: `${action.intervalPx}px` });
}
return {
name: `动作${actionIndex + 1}`,
title: actionTitle,
rows,
materials: parseMaterials(action.materialJson),
};
}),
};
});
}
<!-- 策略详情弹窗 -->
<template>
<div>
<d2-dialog btn-ok-label="确定"
class="detail"
width="70%"
:is-visible.sync="detailVisible"
:title="title"
@closeDialog="handleDetailClose"
@confirmDialog="handleDetailConfirm">
<div class="strategy-detail-dialog">
<template v-if="hasDetail">
<div class="detail-section">
<div class="detail-section-title">
<span>基础信息</span>
</div>
<div class="detail-section-body">
<p v-for="item in basicRows"
:key="item.label">
<span class="detail-label">{{ item.label }}:</span>{{ item.value }}
</p>
</div>
</div>
<div class="detail-section">
<div class="detail-section-title">
<span>目标客户</span>
</div>
<div class="detail-section-body">
<p v-for="item in customerRows"
:key="item.label">
<span class="detail-label">{{ item.label }}:</span>{{ item.value }}
</p>
</div>
</div>
<div class="detail-section">
<div class="detail-section-title">
<span>触发条件</span>
</div>
<div class="detail-section-body">
<p v-for="item in triggerRows"
:key="item.label">
<span class="detail-label">{{ item.label }}:</span>{{ item.value }}
</p>
</div>
</div>
<div class="detail-section">
<div class="detail-section-title">
<span>执行动作</span>
</div>
<div class="detail-section-body">
<template v-if="branchBlocks.length">
<div v-for="(branch, branchIndex) in branchBlocks"
:key="branch.name"
class="branch-block">
<p>
<span class="detail-label">[分支 {{ branchIndex + 1 }}] 触发条件:</span>{{ branch.conditionText }}
</p>
<div v-for="action in branch.actions"
:key="action.name"
class="action-block">
<p>
<span class="detail-label">{{ action.name }}:</span>{{ action.title }}
</p>
<p v-for="row in action.rows"
:key="row.label">
<span class="detail-label">{{ row.label }}:</span>{{ row.value }}
</p>
<p v-if="action.materials.length">
<span class="detail-label">素材内容:</span>
<span v-for="(material, index) in action.materials"
:key="material.url"
class="material-text">
{{ material.typeName }}:{{ material.url }}<span v-if="index < action.materials.length - 1">;</span>
</span>
</p>
</div>
</div>
</template>
<p v-else>
暂无执行动作
</p>
</div>
</div>
</template>
<el-empty v-else
description="暂无详情数据" />
</div>
</d2-dialog>
</div>
</template>
<script>
import {
getBasicRows,
getBranchBlocks,
getCustomerRows,
getTriggerRows,
} from "./detailFormat";
export default {
name: "DetailDialog",
props: {
title: {
type: String,
default: "查看策略详情",
},
detailVisible: {
type: Boolean,
default: false,
},
detailInfo: {
type: Object,
default: () => ({}),
},
},
data() {
return {
info: {},
};
},
computed: {
hasDetail() {
return Object.keys(this.info).length > 0;
},
basicRows() {
return getBasicRows(this.info);
},
customerRows() {
return getCustomerRows(this.info);
},
triggerRows() {
return getTriggerRows(this.info);
},
branchBlocks() {
return getBranchBlocks(this.info);
},
},
watch: {
detailInfo: {
immediate: true,
deep: true,
handler() {
this.initInfo();
},
},
},
methods: {
initInfo() {
const snapshotInfo = this.detailInfo && this.detailInfo.snapshotInfo;
if (!snapshotInfo) {
this.info = {};
return;
}
this.info = JSON.parse(snapshotInfo);
console.log(this.info, "info---");
},
handleDetailConfirm() {
this.$emit("handleDetailConfirm");
},
handleDetailClose() {
this.$emit("handleDetailClose");
},
},
};
</script>
<style lang="scss">
.strategy-detail-dialog {
max-height: 620px;
overflow-y: auto;
padding-right: 6px;
color: #303133;
font-size: 13px;
.detail-section {
margin-bottom: 18px;
&:last-child {
margin-bottom: 0;
}
}
.detail-section-title {
display: flex;
align-items: center;
margin-bottom: 12px;
font-weight: 700;
color: #303133;
span {
padding-right: 12px;
background: #fff;
white-space: nowrap;
}
&::after {
content: "";
flex: 1;
height: 1px;
background: #ebeef5;
}
}
.detail-section-body {
padding: 14px 16px;
border-radius: 4px;
background: #f5f7fa;
line-height: 24px;
p {
margin: 0 0 6px;
word-break: break-all;
&:last-child {
margin-bottom: 0;
}
}
}
.detail-label {
font-weight: 700;
color: #303133;
}
.branch-block {
margin-top: 18px;
&:first-child {
margin-top: 0;
}
}
.action-block {
margin-top: 8px;
}
.material-text {
display: inline;
}
}
</style>
<!-- 关联门店弹窗 -->
<template>
<div>
<d2-dialog btn-ok-label="确定"
class="record"
width="70%"
:is-visible.sync="recordVisible"
:title="title"
@closeDialog="handleRecordClose"
@confirmDialog="handleRecordConfirm">
<d2-table ref="recordTable"
:before-search-fn="beforeSearchFn"
:get-list-api="getListApi"
:search-form="searchFormSearch"
:table-params="tableParams">
<el-button slot="auth-button"
slot-scope="scope"
type="text"
@click="handleDetail(scope.scope)">
查看策略详情
</el-button>
</d2-table>
</d2-dialog>
<RecordDetailDialog v-if="dialog.detailVisible"
:detail-info="dialog.detailInfo"
:detail-visible="dialog.detailVisible"
@handleDetailClose="handleDetailClose"
@handleDetailConfirm="handleDetailClose">
</RecordDetailDialog>
</div>
</template>
<script>
import { Util } from "@/common/util";
import { recordsStrategy } from "@/views/marketingManagement/marketingPushStrategy/api/index";
import recordDetailDialog from "@/views/marketingManagement/marketingPushStrategy/components/recordDetailDialog/index";
export default {
name: "RecordDialog",
components: {
RecordDetailDialog: recordDetailDialog,
},
props: {
title: {
type: String,
default: "查看执行记录",
},
recordVisible: {
type: Boolean,
default: false,
},
strategyId: {
type: String,
default: "",
},
},
data() {
return {
searchFormSearch: {},
getListApi: recordsStrategy,
tableParams: {
btnId: new Date().getTime() + Number.parseInt(Math.random() * 1000),
listName: "list",
tableOption: true,
tableColumns: [{
label: "执行时间",
prop: "executeTime",
formatter: (cellValue) => {
return Util.dateFormate(cellValue.executeTime, "YYYY-MM-DD HH:mm:ss");
},
}, {
label: "执行结果",
prop: "executeResult",
formatter: (cellValue) => {
const obj = {
1: "成功",
2: "失败",
};
return obj[cellValue.executeResult];
},
}, {
label: "描述",
prop: "errorMessage",
}],
},
dialog: {
detailVisible: false,
detailInfo: {},
},
};
},
mounted() {},
methods: {
beforeSearchFn() {
return new Promise((resolve) => {
this.searchFormSearch.strategyId = this.strategyId;
this.searchFormSearch.pageNo = this.$refs.recordTable.page.currentPage || 1;
resolve();
});
},
handleDetailClose() {
this.dialog.detailVisible = !this.dialog.detailVisible;
},
handleDetail(row) {
console.log(row, "row---");
this.handleDetailClose();
this.dialog.detailInfo = row;
},
handleRecordConfirm() {
this.$emit("handleRecordConfirm");
},
handleRecordClose() {
this.$emit("handleRecordClose");
},
},
};
</script>
<style lang="scss">
</style>
<template>
<div class="variable-textarea-wrapper">
<el-input ref="textareaRef"
placeholder="请输入消息内容"
resize="none"
rows="8"
type="textarea"
:value="value"
@input="handleInput">
</el-input>
<div class="foot-wrapper">
<el-dropdown placement="bottom-start"
style="width:100%"
trigger="click"
@command="handleCommand">
<div class="dropdown-wrapper">
<i class="el-icon-plus "></i>
<span class="el-dropdown-link" style="margin-left:8px">
插入变量
</span>
</div>
<el-dropdown-menu slot="dropdown"
class="marketing-dropdown-menu"
style="max-height: 400px; overflow: auto;">
<el-dropdown-item v-for="variable in variableList"
:key="variable.code"
:command="variable.name">
{{ variable.name }}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</div>
</template>
<script>
export default {
name: "VariableTextarea",
props: {
value: {
type: String,
required: true,
},
variableList: {
type: Array,
default: () => ([]),
},
},
data() {
return {
autosize: {
minRows: 6,
maxRows: 60,
},
};
},
computed: {
},
mounted() {
},
methods: {
handleInput(e) {
this.$emit("input", e);
},
handleCommand(command) {
const textarea = this.$refs.textareaRef.$el.querySelector("textarea");
const text = this.value || "";
const insertion = `{{${command}}}`;
if (textarea) {
// 在光标位置插入
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
const newValue = text.substring(0, start) + insertion + text.substring(end);
this.$emit("input", newValue);
this.$nextTick(() => {
const newPos = start + insertion.length;
textarea.setSelectionRange(newPos, newPos);
textarea.focus();
});
} else {
this.$emit("input", text + insertion);
}
},
},
};
</script>
<style scoped lang="scss">
.variable-textarea-wrapper {
border-radius: 4px;
border: 1px solid #e5e5e5;
::v-deep .el-textarea__inner {
border: none;
border-radius: 0;
box-shadow: none;
background-color: #f5f5f5;
color: #666;
}
.foot-wrapper {
background-color: #f5f6fa;
border-top: 1px solid #e5e5e5;
.dropdown-wrapper {
width: 100%;
color: #2a58ad;
cursor: pointer;
display: flex;
align-items: center;
padding: 8px 16px;
}
}
}
</style>
import { nanoid } from "nanoid";
export const actionConfirmOptions = [
{ value: 0, label: "自动执行" },
{ value: 1, label: "需驻店人员确认" },
];
export const MessageTypeEnum = {
VARIABLE_TEXT: 1,
VARIABLE_IMAGE: 2,
VARIABLE_VIDEO: 3,
VARIABLE_WEBPAGE: 4,
};
// 条件的 变量 是 变量 还是值
export const ConditionVariableSourceTypeEnum = {
VARIABLE: 0,
VALUE: 1,
};
export const ConditionVariableTypeEnum = {
TEXT: 1,
NUMBER: 2,
DATE: 3,
ENUM: 4,
};
export const intervalPxOptions = [
{ value: 0, label: "无间隔" },
{ value: 4, label: "4px" },
{ value: 8, label: "8px" },
{ value: 16, label: "16px" },
];
// index: branch 的index
export function getDefaultBranch() {
return {
_key: nanoid(),
conditionGroups: [],
actions: [
getDefaultAction(),
],
};
}
export function getDefaultAction() {
return {
_key: nanoid(),
actionType: undefined,
targetGroupType: 1,
messageType: MessageTypeEnum.VARIABLE_TEXT,
content: "",
medias: [],
pageTitle: undefined,
pageDesc: undefined,
bgColor: undefined,
materialJson: [],
intervalPx: undefined,
};
}
export const bizTypeOpt = [
{ confId: 1, confLabel: "轻改" },
];
export const storeTypeOpt = [
{ confId: 1, confLabel: "指定门店" },
{ confId: 0, confLabel: "不限门店" },
];
export const relativeDateTypeOpt = [
{ code: 0, name: "提前" },
{ code: 1, name: "当天" },
{ code: 2, name: "推后" },
];
// 生成小时选项 00-23
export const hourOptions = Array.from({ length: 24 }, (_, i) => String(i).padStart(2, "0"));
// 生成分钟选项 00-59
export const minuteOptions = Array.from({ length: 60 }, (_, i) => String(i).padStart(2, "0"));
// 如果别的模块需要这个模块的内容, 在这里引入本模块的东西 然后导出
// 别的模块使用 @\views\marketingManage\marketingActive 路径进行导入
/**
* 将文本中的 {{ code }} 替换为数组中对应 item 的 {{ name }}
* @param {string} text - 包含 {{ code }} 占位符的文本
* @param {Array<{code: string, name: string}>} arr - 映射数组
* @returns {string} 替换后的文本
*/
export function replaceCodeWithName(text, arr) {
return text.replace(/\{\{\s*(\S+?)\s*\}\}/g, (match, code) => {
const item = arr.find(item => item.code === code);
return item ? `{{ ${item.name} }}` : match;
});
}
/**
* 将文本中的 {{ name }} 替换为数组中对应 item 的 {{ code }}
* @param {string} text - 包含 {{ name }} 占位符的文本
* @param {Array<{code: string, name: string}>} arr - 映射数组
* @returns {string} 替换后的文本
*/
export function replaceNameWithCode(text, arr) {
let result = text;
arr.forEach((item) => {
result = result.replace(
new RegExp(`\\{\\{\\s*${escapeRegExp(item.name)}\\s*\\}\\}`, "g"),
`{{ ${item.code} }}`,
);
});
return result;
}
function escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
import { bizTypeOpt, storeTypeOpt } from "@/views/marketingManagement/marketingPushStrategy/constant";
import { actionConfirmOptions } from "@/views/marketingManagement/marketingPushStrategy/constant/index";
export function getModifySchema() {
return [
{
addHtml: "_label3",
},
{
label: "动作执行确认",
name: "actionConfirmType",
type: "radio",
optionList: actionConfirmOptions,
optionId: "value",
optionLabel: "label",
},
{
labelWidth: "0px",
addHtml: "_branchList",
},
];
}
export const rules = {
strategyName: [
{ required: true, message: "请输入策略名称", trigger: "change" },
],
bizType: [
{ required: true, message: "请选择适用场景", trigger: "change" },
],
storeScopeType: [
{ required: true, message: "请选择适用门店", trigger: "change" },
],
storeIds: [
{
required: true,
validator(rule, value, callback, source) {
if (source.storeScopeType == 0 || (Array.isArray(value) && value.length)) {
callback();
return;
}
callback(new Error("请选择指定门店"));
},
trigger: "change",
},
],
marketingStage: [
{ required: true, message: "请选择营销阶段", trigger: "change" },
],
triggerType: [
{ required: true, message: "请选择触发类型", trigger: "change" },
],
dateVariableType: [
{ required: true, message: "请选择日期时间变量", trigger: "change" },
],
relativeDateType: [
{ required: true, message: "请选择实际触发时间", trigger: "change" },
],
step2ConditionGroups: [
{ required: true, message: "请添加条件", trigger: "change" },
],
};
export function getFormSchema(that, stageOptions) {
return [
{
label: "策略名称",
name: "strategyName",
type: "input",
maxlength: 40,
},
{
label: "适用场景",
name: "bizType",
type: "radio",
optionList: bizTypeOpt,
optionId: "confId",
optionLabel: "confLabel",
},
{
label: "适用门店",
name: "storeScopeType",
type: "radio",
optionList: storeTypeOpt,
optionId: "confId",
optionLabel: "confLabel",
},
{
label: "选择指定门店",
name: "storeIds",
addHtml: "storeIds",
isHide: ({ formModel }) => {
return formModel.storeScopeType === 0;
},
},
{
label: "营销阶段",
name: "marketingStage",
type: "select",
optionList: stageOptions,
optionId: "stageCode",
optionLabel: "stageName",
optionsName: "stages",
suffixSlot: "stageSlot",
changeAttr: (val, schemaItem) => {
const list = schemaItem.optionList.find(item => item.stageCode === val)?.triggerMetaDates || [];
that.setTriggerMetaDateOptions(list);
},
},
];
}
function isDateTimeTrigger(triggerType) {
return triggerType === "DATE_TIME";
}
export function getSpecFormSchema(that, triggers, triggerMetaDates) {
return [
{
label: "触发类型",
name: "triggerType",
type: "select",
optionList: triggers,
optionId: "code",
optionLabel: "name",
},
{
label: "日期时间变量",
name: "dateVariableType",
type: "select",
optionList: triggerMetaDates,
optionId: "code",
optionLabel: "name",
isHide: ({ formModel }) => {
return !isDateTimeTrigger(formModel.triggerType);
},
},
{
label: "实际触发时间",
name: "relativeDateType",
addHtml: "actualTriggerTime",
isHide: ({ formModel }) => {
return !isDateTimeTrigger(formModel.triggerType);
},
},
{
label: "同时满足以下条件",
name: "step2ConditionGroups",
addHtml: "step2ConditionGroups",
rules: [
{ required: true, message: "请添加条件", trigger: "change", type: "array" },
],
isHide: ({ formModel }) => {
return !isDateTimeTrigger(formModel.triggerType);
},
},
];
}
<template>
<div class="wrapper">
<div style="margin-left:30px;padding">
<glsx-combi-form label-width="150px"
:form-data="formSchema"
:form-obj="form"
:form-rules="formRules"
:inline="false">
<template #_branchList>
<el-form label-width="150px" size="small">
<BranchItem v-for="(branch, index) in form.branches"
:key="branch._key"
:branch="branch"
:options="{
messageVariables: options.messageVariables,
triggers: options.triggers,
}"
:title="`分支${index + 1}`"
@appendAction="handleAppendAction(index)"
@input="handleBranchChange($event, index)"
@removeAction="handleRemoveAction($event, index)"
@removeBranch="handleRemoveBranch(index)" />
<el-button block @click="handleAppendBranch">
<i class="el-icon-plus "></i>
添加分支
</el-button>
</el-form>
</template>
</glsx-combi-form>
</div>
<!-- <div class="step3-wrapper">
<div class="title-wrapper">
③ 就执行以下动作
</div>
</div>
<glsx-combi-form default-width="400px"
label-width="150px"
:form-data="formSchema"
:form-obj="form"
:form-rules="formRules">
<template #_label4>
<div>默认执行第一条满足条件规则的分支</div>
</template>
</glsx-combi-form> -->
<!-- <div style="width:800px">
<ConditionGroup style="width:880px;margin:0 0 0 30px;padding-top:30px;"
:options="{
conditionVariables: getStep2ConditionOptions,
}" />
</div> -->
</div>
</template>
<script>
import { nanoid } from "nanoid";
import { getMetaOptions } from "@/views/marketingManagement/marketingPushStrategy/api/index.js";
import BranchItem from "@/views/marketingManagement/marketingPushStrategy/components/branchItem/index.vue";
import ConditionGroup from "@/views/marketingManagement/marketingPushStrategy/components/conditionGroup/index.vue";
import VariableTextarea from "@/views/marketingManagement/marketingPushStrategy/components/variableTextarea/index.vue";
import { getDefaultAction, getDefaultBranch, MessageTypeEnum } from "@/views/marketingManagement/marketingPushStrategy/constant";
import { replaceCodeWithName } from "@/views/marketingManagement/marketingPushStrategy/utils/index.js";
import { getModifySchema } from "./modify.data";
export default {
name: "",
components: {
BranchItem,
ConditionGroup,
VariableTextarea,
},
props: {
},
data() {
return {
test: "123",
form: {
actionConfirmType: 0,
branches: [getDefaultBranch()],
},
formSchema: [],
formRules: {},
options: {
conditionVariables: [],
step2ConditionVariables: [],
stages: [],
triggers: [],
messageVariables: [],
},
};
},
computed: {
getStep2ConditionOptions() {
return this.options.step2ConditionVariables;
},
},
async mounted() {
this.formSchema = await getModifySchema();
await this.getData();
},
methods: {
handleSubmit() {
console.log(this.form);
},
handleRemoveAction(actionIndex, branchIndex) {
this.form.branches[branchIndex].actions.splice(actionIndex, 1);
},
handleAppendBranch() {
this.form.branches.push(getDefaultBranch());
},
handleRemoveBranch(branchIndex) {
this.form.branches.splice(branchIndex, 1);
},
handleAppendAction(branchIndex) {
this.form.branches[branchIndex].actions.push(getDefaultAction());
},
handleBranchChange({ actionIndex, actionItem }, branchIndex) {
this.$set(this.form.branches[branchIndex].actions, actionIndex, actionItem);
},
async getData() {
const data = await getMetaOptions();
Object.assign(this.options, data);
},
},
};
</script>
<style scoped lang="scss">
.wrapper {
background-color: white;
height: 100%;
margin: 0 20px 20px;
::v-deep .branch-item-wrapper {
margin-top: 12px;
&:first-child {
margin-top: 0;
}
}
}
</style>
<!-- 对账单模版管理 - 列表 -->
<template>
<div>
<d2-container>
<div slot="header"
class="header"
style="padding: 10px 20px;">
<d2-search ref="showSearch"
class="show-search"
:form-data="showFormData"
:label-width="labelWidth"
:search-form="searchForm">
</d2-search>
<div class="up-btns">
<el-button size="small"
type="primary"
@click="handleSearch">
查询
</el-button>
<el-button size="small" @click="handleReset">
重置
</el-button>
</div>
</div>
<div class="d2-container-content">
<d2-table-header>
<auth-button category="Button"
:data="{ operate: 'create' }"
:show-btn-ids="['9221001']" />
</d2-table-header>
<d2-table ref="marketTable"
:before-search-fn="beforeSearchFn"
:get-list-api="getListApi"
:search-form="searchFormSearch"
:table-params="tableParams">
<div slot="status" slot-scope="scope">
<el-switch v-model="scope.scope.status"
active-color="#2A58AD"
inactive-color="#CCCCCC"
:active-value="1"
:inactive-value="0"
@change="handleChangeStatus(scope.scope)">
</el-switch>
</div>
<auth-button slot="auth-button"
slot-scope="scope"
:data="scope.scope" />
</d2-table>
</div>
</d2-container>
<RecordDialog v-if="dialog.recordVisible"
:record-visible="dialog.recordVisible"
:strategy-id="dialog.strategyId"
@handleRecordClose="handleRecordClose"
@handleRecordConfirm="handleRecordClose">
</RecordDialog>
</div>
</template>
<script>
import { deepClone, Util } from "@/common/util";
import reportTrackFunMixin from "@/mixins/reportTrackFunMixin";
import { deleteStrategy, getList, statusStrategy } from "@/views/marketingManagement/marketingPushStrategy/api/index";
import recordDialog from "@/views/marketingManagement/marketingPushStrategy/components/recordDialog/index";
export default {
name: "MarketingPush",
components: {
RecordDialog: recordDialog,
},
mixins: [reportTrackFunMixin], // 导入混入
data() {
return {
userInfo: this.$store.state.d2admin.user.info,
labelWidth: "110px",
searchForm: {
strategyName: "",
status: "",
},
searchFormSearch: {},
showFormData: [
{
label: "策略名称",
name: "strategyName",
type: "input",
maxlength: "40",
},
{
label: "状态",
name: "status",
type: "select",
optionList: [],
optionId: "confId",
optionLabel: "confLabel",
optionsName: "statusList",
},
],
getListApi: getList,
tableParams: {
btnId: new Date().getTime() + Number.parseInt(Math.random() * 1000),
listName: "list",
tableOption: true,
tableColumns: [{
label: "策略名称",
prop: "strategyName",
}, {
label: "最近修改时间",
prop: "updatedDate",
formatter: (cellValue) => {
return Util.dateFormate(cellValue.updatedDate, "YYYY-MM-DD HH:mm");
},
}, {
label: "最近修改人",
prop: "updatedBy",
}, {
label: "状态",
prop: "status",
width: "124px",
addHtml: "status",
}],
},
// 弹窗
dialog: {
recordVisible: false,
strategyId: "",
},
baseData: {
statusList: [{
confId: 1,
confLabel: "启用",
}, {
confId: 0,
confLabel: "停用",
}],
},
};
},
mounted() {
this.setReportTrackData(0, "sop_strategy_web_menu_entry", {});
this.getOptionsList("showFormData");
},
methods: {
// ...mapActions({
// get: 'd2admin/base/get',
// close: 'd2admin/page/close'
// }),
// ...mapActions('d2admin/user', ['actionSetDownloadList']),
beforeSearchFn() {
return new Promise((resolve) => {
this.searchFormSearch = deepClone(this.searchForm);
this.searchFormSearch.pageNo = this.$refs.marketTable.page.currentPage || 1;
resolve();
});
},
getOptionsList(formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
let item = this[formName].find(k => k.name == refreshSigle);
let index = this[formName].findIndex(k => k.name == refreshSigle);
this.$set(this[formName][index], "optionList", deepClone(this.baseData[item.optionsName]));
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== "全部") {
const temp = {};
temp[this[formName][index].optionId] = "";
temp[this[formName][index].optionLabel] = "全部";
this[formName][index].optionList.unshift(temp);
}
} else {
this[formName].forEach((item, index) => {
if (item.type === "select" && this.baseData[item.optionsName].length) {
this.$set(this[formName][index], "optionList", deepClone(this.baseData[item.optionsName]));
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== "全部") {
const temp = {};
temp[this[formName][index].optionId] = "";
temp[this[formName][index].optionLabel] = "全部";
this[formName][index].optionList.unshift(temp);
}
}
});
}
},
handleSearch() {
this.$refs.marketTable.refreshTable(false, true);
},
handleReset() {
this.searchForm = {
strategyName: "",
status: "",
};
this.$refs.marketTable.refreshTable(false, true);
},
// 执行记录
handleRecord(row) {
this.handleRecordClose();
this.dialog.strategyId = (row?.id + "") || "";
},
handleRecordClose() {
this.dialog.recordVisible = !this.dialog.recordVisible;
},
// 新增 / 修改
handleModify(row = {}) {
const editType = row?.id ? "edit" : "add";
this.$router.push({
path: "/marketing-push-strategy/modify",
query: {
editType,
strategyId: row?.id || "",
},
});
},
handleChangeStatus(row) {
const params = {
strategyId: row.id,
status: row.status,
};
statusStrategy(params).then((res) => {
this.$message.success("操作成功");
this.handleReset();
});
},
handleDelete(row) {
this.$confirm(`确定要删除策略"${row.strategyName}"吗?`, "删除策略", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
const params = { strategyId: row.id };
deleteStrategy(params).then((res) => {
this.$message.success("操作成功");
this.handleReset();
});
}).catch(() => { });
},
},
};
</script>
<style scoped>
.count-txt {
font-weight: 700;
color: #2a58ad;
margin: 0 2px;
}
.leftSpan {
display: inline-block;
box-sizing: border-box;
margin-right: 10px;
}
.fields-txt {
width: 346px;
display: inline-block;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!