ny
22 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<script lang="ts" setup>
import { computed, reactive, toRefs } from 'vue';
 
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { BasicVxeTable, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { getInfo } from '#/api/msgCenter/msgTemplate';
import { useBaseStore } from '#/store';
 
defineEmits(['register']);
 
interface State {
  dataForm: any;
  parameterList: any[];
  allParameterList: any[];
  smsList: any[];
  messageTypeList: any[];
  messageSourceList: any[];
  keyword: string;
}
 
const state = reactive<State>({
  dataForm: {
    id: '',
    fullName: '',
    enCode: '',
    templateType: 0,
    messageType: '',
    messageSource: '',
    enabledMark: 1,
    sortCode: 0,
    description: '',
    title: '',
    content: '',
    templateCode: '',
    wxSkip: '1',
    xcxAppId: '',
  },
  parameterList: [],
  allParameterList: [],
  smsList: [],
  messageTypeList: [],
  messageSourceList: [],
  keyword: '',
});
const { dataForm, keyword, parameterList, smsList } = toRefs(state);
const parameterColumns = [
  { title: '参数名称', dataIndex: 'field', key: 'field', width: 170 },
  { title: '参数说明', dataIndex: 'fieldName', key: 'fieldName', width: 170 },
];
const [registerTable] = useVxeTable({
  columns: parameterColumns,
  useSearchForm: false,
  showTableSetting: false,
  pagination: false,
  showHeader: false,
  showIndexColumn: false,
});
 
const getSmsParameterColumns = computed(() => {
  const baseColumns: any[] = [
    { title: '序号', dataIndex: 'index', key: 'index', align: 'center', width: 50, customRender: ({ index }) => index + 1 },
    {
      title: '变量',
      dataIndex: 'smsField',
      key: 'smsField',
      helpMessage: ['阿里云:在【阿里云管理后台-模板管理】维护模板变量参数', '腾讯云:在【腾讯云管理后台-正⽂模板管理】维护模板变量参数'],
    },
    { title: '参数', dataIndex: 'field', key: 'field', width: 200 },
    { title: '标题', dataIndex: 'isTitle', key: 'isTitle', width: 70, align: 'center' },
  ];
  let list: any[] = [];
  if (state.dataForm.messageType == 3) {
    list = baseColumns.filter((o) => o.key != 'isTitle');
  } else {
    list = baseColumns;
    list[1].helpMessage = '在【微信公众号管理后台-广告与服务-模板消息】维护模板参数';
  }
  return list;
});
const baseStore = useBaseStore();
const [registerModal, { changeLoading }] = useModalInner(init);
 
async function init(data) {
  resetForm();
  state.dataForm.id = data.id || '';
  if (state.dataForm.id) {
    initData();
    changeLoading(true);
    state.messageSourceList = (await baseStore.getDictionaryData('msgSourceType')) as any[];
    state.messageSourceList.map((o) => (o.id = o.enCode));
    getInfo(state.dataForm.id)
      .then((res) => {
        changeLoading(false);
        res.data.smsFieldList.forEach((o) => {
          o.isTitle = !!o.isTitle;
        });
        state.dataForm = res.data;
        state.parameterList = res.data.templateParamList;
        state.allParameterList = state.parameterList;
        state.smsList = res.data.smsFieldList;
        const sourceItem = state.messageSourceList.find((item) => {
          return item.enCode == state.dataForm.messageSource;
        });
        const typeItem = state.messageTypeList.find((item) => {
          return item.enCode == state.dataForm.messageType;
        });
        if (sourceItem) state.dataForm.messageSourceVal = sourceItem.fullName;
        if (typeItem) state.dataForm.messageTypeVal = typeItem.fullName;
      })
      .catch(() => {
        changeLoading(false);
      });
  }
}
async function initData() {
  state.messageTypeList = (await baseStore.getDictionaryData('msgSendType')) as any[];
  state.messageTypeList.map((o) => (o.id = o.enCode));
}
function handleSearch() {
  state.parameterList = state.allParameterList.filter((item) => {
    return item.field.toLowerCase().includes(state.keyword.toLowerCase()) || item.fieldName.toLowerCase().includes(state.keyword.toLowerCase());
  });
}
function resetForm() {
  state.dataForm = {
    id: '',
    fullName: '',
    enCode: '',
    templateType: 0,
    messageType: '',
    messageSource: '',
    enabledMark: 1,
    sortCode: 0,
    description: '',
    title: '',
    content: '',
    templateCode: '',
    wxSkip: 1,
    xcxAppId: '',
  };
  state.smsList = [];
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="查看模板" :footer="null" :width="1000">
    <a-form class="!mx-[20px]" :colon="false" :model="dataForm" :label-col="{ style: { width: '100px' } }">
      <a-row :gutter="20">
        <a-col :span="12">
          <a-form-item label="名称" name="fullName">
            <p>{{ dataForm.fullName }}</p>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="编码" name="enCode">
            <p>{{ dataForm.enCode }}</p>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="模板类型">
            <p>{{ dataForm.templateType == '0' ? '自定义模板' : '系统模板' }}</p>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="消息来源" name="messageSource">
            <p>{{ dataForm.messageSourceVal }}</p>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="消息类型" name="messageType">
            <p>{{ dataForm.messageTypeVal }}</p>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="状态" name="enabledMark">
            <a-switch v-model:checked="dataForm.enabledMark" :checked-value="1" :un-checked-value="0" disabled />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="排序" name="sortCode">
            <p>{{ dataForm.sortCode }}</p>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="说明" name="description">
            <p>{{ dataForm.description }}</p>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <div class="msg-parameter-box">
            <div class="left-pane">
              <div class="left-pane-list">
                <div class="list">
                  <div class="header detail-header">
                    <span>参数名称</span>
                    <span>参数说明</span>
                  </div>
                  <div class="search-box">
                    <a-input-search class="search" v-model:value="keyword" placeholder="输入关键字" allow-clear @input="handleSearch" />
                  </div>
                  <BasicVxeTable @register="registerTable" :data-source="parameterList">
                    <template #bodyCell="{ column, record }">
                      <template v-if="column.key === 'field'">
                        <span class="cursor-pointer" :title="record.field">{{ record.field }}</span>
                      </template>
                      <template v-if="column.key === 'fieldName'">
                        <span class="cursor-pointer" :title="record.fieldName">
                          {{ record.fieldName }}
                        </span>
                      </template>
                    </template>
                  </BasicVxeTable>
                </div>
              </div>
            </div>
            <div class="right-pane" v-if="dataForm.messageType != 3 && dataForm.messageType != 7">
              <a-form-item name="title">
                <template #label>消息标题<BasicHelp text="参数格式:{参数名}" /></template>
                <p>{{ dataForm.title }}</p>
              </a-form-item>
              <a-form-item name="content" v-if="dataForm.messageType == 2">
                <template #label>消息内容<BasicHelp text="参数格式:{参数名}" /></template>
                <p v-html="dataForm.content"></p>
              </a-form-item>
              <a-form-item name="content" v-else-if="dataForm.messageType != 1">
                <template #label>消息内容<BasicHelp text="参数格式:{参数名}" /></template>
                <p>{{ dataForm.content }}</p>
              </a-form-item>
            </div>
            <div class="right-pane" v-else>
              <a-row :gutter="20">
                <a-col :span="24">
                  <a-form-item name="templateCode">
                    <template #label>
                      模板编号
                      <BasicHelp
                        :text="
                          dataForm.messageType == 3
                            ? ['阿里云:请在【阿里云管理后台-模板管理】⻚⾯查看模板CODE', '腾讯云:请在【腾讯云管理后台-正⽂模板管理】⻚⾯查看模板ID']
                            : '在【微信公众号管理后台-广告与服务-模板消息】⻚⾯查看模板ID'
                        " />
                    </template>
                    <p>{{ dataForm.templateCode }}</p>
                  </a-form-item>
                </a-col>
                <a-col :span="12" v-if="dataForm.messageType == 7">
                  <a-form-item label="跳转方式" name="wxSkip">
                    <p>{{ dataForm.wxSkip == 1 ? '小程序' : '页面' }}</p>
                  </a-form-item>
                </a-col>
                <a-col :span="12" v-if="dataForm.messageType == 7 && dataForm.wxSkip == 1">
                  <a-form-item name="xcxAppId">
                    <template #label>消息内容<BasicHelp text="请在【微信公众号管理后台-广告与服务-小程序管理】⻚⾯查看小程序ID" /></template>
                    <p>{{ dataForm.xcxAppId }}</p>
                  </a-form-item>
                </a-col>
              </a-row>
              <div class="msg-pane">
                <div class="list">
                  <a-table :data-source="smsList" :columns="getSmsParameterColumns" size="small" :pagination="false">
                    <template #headerCell="{ column }">
                      <template v-if="column.key === 'smsField'">
                        <span>{{ column.title }}</span>
                        <BasicHelp :text="column.helpMessage" />
                      </template>
                    </template>
                    <template #bodyCell="{ column, record }">
                      <template v-if="column.key === 'smsField'">
                        <p>{{ record.smsField }}</p>
                      </template>
                      <template v-if="column.key === 'field'">
                        <p>{{ record.field }}</p>
                      </template>
                      <template v-if="column.key === 'isTitle'">
                        <a-checkbox v-model:checked="record.isTitle" disabled />
                      </template>
                    </template>
                  </a-table>
                </div>
              </div>
            </div>
          </div>
        </a-col>
      </a-row>
    </a-form>
  </BasicModal>
</template>
<style lang="scss" scoped>
.left-pane {
  height: 323px;
}
</style>