sms-test-send-dialog.vue
5.34 KB
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
<template>
<el-dialog
title="测试发送"
:visible.sync="visible"
width="640px"
append-to-body
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="form" label-width="90px" size="small">
<el-form-item label="场景">
<el-select v-model="form.sceneCode" style="width: 100%" @change="onSceneChange">
<el-option label="生日 Birthday" value="Birthday" />
<el-option label="登录 Login" value="Login" />
<el-option label="注册 Register" value="Register" />
<el-option label="验证码 VerifyCode" value="VerifyCode" />
</el-select>
</el-form-item>
<el-form-item label="手机号">
<el-input v-model="form.mobile" clearable placeholder="测试手机号" maxlength="11" />
</el-form-item>
<el-form-item label="姓名变量">
<el-input v-model="form.name" clearable placeholder="{name}" />
</el-form-item>
<el-form-item v-if="form.sceneCode !== 'Birthday'" label="验证码">
<el-input v-model="form.code" clearable placeholder="{code}" maxlength="8" />
</el-form-item>
</el-form>
<div class="sms-test-actions">
<el-button type="primary" size="small" :loading="testSending" @click="doTestSend">测试发送</el-button>
<el-button size="small" :loading="previewLoading" @click="doPreviewBirthday">预览今日生日</el-button>
<el-button type="warning" size="small" :loading="birthdaySending" @click="doSendBirthday(true)">试跑(不发)</el-button>
<el-button type="danger" size="small" :loading="birthdaySending" @click="confirmSendBirthday">发送今日生日短信</el-button>
</div>
<p v-if="resultText" class="sms-test-result">{{ resultText }}</p>
<div slot="footer">
<el-button size="small" @click="visible = false">关 闭</el-button>
</div>
</el-dialog>
</template>
<script>
import {
sendSmsByScene,
previewBirthdayMembers,
sendBirthdaySms
} from '@/api/extend/lqSms'
const emptyForm = () => ({
mobile: '',
name: '测试会员',
code: '123456',
sceneCode: 'Birthday'
})
export default {
name: 'SmsTestSendDialog',
data() {
return {
visible: false,
testSending: false,
previewLoading: false,
birthdaySending: false,
resultText: '',
form: emptyForm()
}
},
methods: {
open() {
this.form = emptyForm()
this.resultText = ''
this.visible = true
},
handleClose() {
this.form = emptyForm()
this.resultText = ''
},
onSceneChange() {
if (this.form.sceneCode !== 'Birthday' && !this.form.code) {
this.form.code = '123456'
}
},
doTestSend() {
if (!this.form.mobile) {
this.$message.warning('请填写测试手机号')
return
}
this.testSending = true
const variables = { name: this.form.name || '测试会员' }
if (this.form.sceneCode !== 'Birthday') {
variables.code = this.form.code || '123456'
}
sendSmsByScene({
sceneCode: this.form.sceneCode,
mobile: this.form.mobile,
variables,
memberName: this.form.name,
isTest: true,
skipDuplicateCheck: true
}).then(res => {
const data = (res && res.data) || {}
const tip = `发送完成:${data.statusName || ''} ${data.providerResult || ''}`
this.resultText = tip
this.$message.success(tip)
this.$emit('success')
}).finally(() => {
this.testSending = false
})
},
doPreviewBirthday() {
this.previewLoading = true
previewBirthdayMembers({}).then(res => {
const data = (res && res.data) || {}
this.resultText = `${data.bizDate || ''} 共 ${data.total || 0} 位生日会员(有手机号方可发送)`
}).finally(() => {
this.previewLoading = false
})
},
doSendBirthday(dryRun) {
this.birthdaySending = true
sendBirthdaySms({ dryRun: !!dryRun }).then(res => {
const data = (res && res.data) || {}
if (dryRun) {
this.resultText = `试跑:候选 ${data.total || 0} 人,有手机号 ${data.withMobile || 0} 人`
this.$message.success('试跑完成(未实际发送)')
} else {
this.resultText = `发送完成:成功 ${data.success || 0} / 失败 ${data.failed || 0} / 跳过 ${data.skipped || 0}`
this.$message.success('生日短信发送完成')
this.$emit('success')
}
}).finally(() => {
this.birthdaySending = false
})
},
confirmSendBirthday() {
this.$confirm('确认向今日生日会员发送短信?将产生阿里云短信费用。', '确认发送', {
type: 'warning'
}).then(() => {
this.doSendBirthday(false)
}).catch(() => {})
}
}
}
</script>
<style lang="scss" scoped>
.sms-test-actions {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
gap: 8px;
margin: 4px 0 12px;
}
.sms-test-result {
margin: 0;
padding: 10px 12px;
border-radius: 4px;
background: #f4f4f5;
color: #606266;
font-size: 13px;
line-height: 1.6;
}
</style>
<style lang="scss">
/* append-to-body:暗黑需挂 body / #app */
body.ncc-content-dark .sms-test-result,
#app .ncc-content-dark .sms-test-result {
background: rgba(255, 255, 255, 0.08);
color: rgba(255, 255, 255, 0.75);
}
</style>