index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <content-wrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. :model="queryParams"
  6. ref="queryForm"
  7. :inline="true"
  8. v-show="showSearch"
  9. label-width="150px"
  10. >
  11. <el-form-item label="短信类型" prop="type">
  12. <el-select v-model="queryParams.type" placeholder="请选择短信类型" clearable>
  13. <el-option
  14. v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE)"
  15. :key="dict.value"
  16. :label="dict.label"
  17. :value="dict.value"
  18. />
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="开启状态" prop="status">
  22. <el-select v-model="queryParams.status" placeholder="请选择开启状态" clearable>
  23. <el-option
  24. v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
  25. :key="dict.value"
  26. :label="dict.label"
  27. :value="dict.value"
  28. />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="模板编码" prop="code">
  32. <el-input
  33. v-model="queryParams.code"
  34. placeholder="请输入模板编码"
  35. clearable
  36. @keyup.enter="handleQuery"
  37. />
  38. </el-form-item>
  39. <el-form-item label="短信 API 的模板编号" prop="apiTemplateId">
  40. <el-input
  41. v-model="queryParams.apiTemplateId"
  42. placeholder="请输入短信 API 的模板编号"
  43. clearable
  44. @keyup.enter="handleQuery"
  45. />
  46. </el-form-item>
  47. <el-form-item label="短信渠道" prop="channelId">
  48. <el-select v-model="queryParams.channelId" placeholder="请选择短信渠道" clearable>
  49. <el-option
  50. v-for="channel in channelOptions"
  51. :key="channel.id"
  52. :value="channel.id"
  53. :label="
  54. channel.signature + optionLabel(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE, channel.code)
  55. "
  56. />
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item label="创建时间" prop="createTime">
  60. <el-date-picker
  61. v-model="queryParams.createTime"
  62. style="width: 240px"
  63. type="daterange"
  64. value-format="YYYY-MM-DD HH:mm:ss"
  65. start-placeholder="开始日期"
  66. end-placeholder="结束日期"
  67. />
  68. </el-form-item>
  69. <el-form-item>
  70. <el-button type="primary" @click="handleQuery"
  71. ><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button
  72. >
  73. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  74. </el-form-item>
  75. </el-form>
  76. <!-- 操作工具栏 -->
  77. <el-row class="mb-10px">
  78. <el-col :span="12">
  79. <el-row :gutter="10">
  80. <el-col :span="1.5">
  81. <el-button
  82. type="primary"
  83. plain
  84. @click="handleAdd('template.addTitle')"
  85. v-hasPermi="['system:sms-template:create']"
  86. ><Icon icon="ep:plus" class="mr-5px" />新增</el-button
  87. >
  88. </el-col>
  89. <el-col :span="1.5">
  90. <el-button
  91. type="success"
  92. plain
  93. @click="handleExport"
  94. :loading="exportLoading"
  95. v-hasPermi="['system:sms-template:export']"
  96. >
  97. <Icon icon="ep:download" class="mr-5px" /> 导出
  98. </el-button>
  99. </el-col>
  100. </el-row>
  101. </el-col>
  102. <el-col :span="12">
  103. <right-toolbar v-model:showSearch="showSearch" @query-table="getList" />
  104. </el-col>
  105. </el-row>
  106. <!-- 列表 -->
  107. <el-table v-loading="loading" :data="templateList" align="center">
  108. <el-table-column
  109. label="模板编码"
  110. align="center"
  111. prop="code"
  112. width="120"
  113. :show-overflow-tooltip="true"
  114. />
  115. <el-table-column
  116. label="模板名称"
  117. align="center"
  118. prop="name"
  119. width="120"
  120. :show-overflow-tooltip="true"
  121. />
  122. <el-table-column
  123. label="模板内容"
  124. align="center"
  125. prop="content"
  126. width="200"
  127. :show-overflow-tooltip="true"
  128. />
  129. <el-table-column label="短信类型" align="center" prop="type">
  130. <template #default="scope">
  131. <dict-tag :type="DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE" :value="scope.row.type" />
  132. </template>
  133. </el-table-column>
  134. <el-table-column label="状态" align="center" prop="status" width="80">
  135. <template #default="scope">
  136. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  137. </template>
  138. </el-table-column>
  139. <el-table-column label="备注" align="center" prop="remark" />
  140. <el-table-column
  141. label="短信 API 的模板编号"
  142. align="center"
  143. prop="apiTemplateId"
  144. width="200"
  145. :show-overflow-tooltip="true"
  146. />
  147. <el-table-column label="短信渠道" align="center" width="120">
  148. <template #default="scope">
  149. <div>{{ formatChannelSignature(scope.row.channelId) }}</div>
  150. <dict-tag :type="DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE" :value="scope.row.channelCode" />
  151. </template>
  152. </el-table-column>
  153. <el-table-column
  154. label="创建时间"
  155. align="center"
  156. prop="createTime"
  157. width="180"
  158. :formatter="dateFormatter"
  159. />
  160. <el-table-column
  161. label="操作"
  162. align="center"
  163. class-name="small-padding fixed-width"
  164. width="210"
  165. fixed="right"
  166. >
  167. <template #default="scope">
  168. <el-button
  169. link
  170. type="primary"
  171. @click="handleSendSms('template.sendSms', scope.row)"
  172. v-hasPermi="['system:sms-template:send-sms']"
  173. ><Icon icon="ep:share" class="mr-3px" />测试</el-button
  174. >
  175. <el-button
  176. link
  177. type="primary"
  178. @click="handleUpdate('template.updtaeTitle', scope.row)"
  179. v-hasPermi="['system:sms-template:update']"
  180. ><Icon icon="ep:edit" class="mr-3px" />修改</el-button
  181. >
  182. <el-button
  183. link
  184. type="primary"
  185. @click="handleDelete(scope.row)"
  186. v-hasPermi="['system:sms-template:delete']"
  187. ><Icon icon="ep:delete" class="mr-3px" />删除</el-button
  188. >
  189. </template>
  190. </el-table-column>
  191. </el-table>
  192. <!-- 分页 -->
  193. <Pagination
  194. :total="total"
  195. v-model:page="queryParams.pageNo"
  196. v-model:limit="queryParams.pageSize"
  197. @pagination="getList"
  198. />
  199. </content-wrap>
  200. <!-- 表单弹窗:添加/修改 -->
  201. <SmsTemplateFrom ref="modalRef" :channelOptions="channelOptions" @success="getList" />
  202. </template>
  203. <script setup lang="ts" name="SmsTemplate">
  204. import { DICT_TYPE, getDictOptions, getDictLabel } from '@/utils/dict'
  205. import { dateFormatter } from '@/utils/formatTime'
  206. import * as templateApi from '@/api/system/sms/smsTemplate'
  207. import * as SmsChannelApi from '@/api/system/sms/smsChannel'
  208. import download from '@/utils/download'
  209. import SmsTemplateFrom from './form.vue'
  210. const message = useMessage() // 消息弹窗
  211. // const { t } = useI18n() // 国际化
  212. // 弹出层ref
  213. const modalRef = ref()
  214. // 遮罩层
  215. const loading = ref(true)
  216. // 导出遮罩层
  217. // const exportLoading = ref(false)
  218. // 显示搜索条件
  219. const showSearch = ref(true)
  220. // 表单ref
  221. const queryForm = ref()
  222. // 查询参数
  223. const queryParams = ref<templateApi.SmsTemplatePageReqVO>({
  224. pageNo: 1,
  225. pageSize: 10,
  226. type: null,
  227. status: null,
  228. code: '',
  229. content: '',
  230. apiTemplateId: '',
  231. channelId: null,
  232. createTime: []
  233. })
  234. // 总条数
  235. const total = ref(0)
  236. // 短信模板列表
  237. const templateList = ref([])
  238. /** 查询列表 */
  239. const getList = () => {
  240. loading.value = true
  241. // 执行查询
  242. templateApi.getSmsTemplatePageApi(queryParams.value).then((response) => {
  243. templateList.value = response.list
  244. total.value = response.total
  245. loading.value = false
  246. })
  247. }
  248. /** 搜索按钮操作 */
  249. const handleQuery = () => {
  250. queryParams.value.pageNo = 1
  251. getList()
  252. }
  253. /** 重置按钮操作 */
  254. const resetQuery = () => {
  255. resetForm()
  256. handleQuery()
  257. }
  258. /** 重置搜索表单 */
  259. const resetForm = () => {
  260. queryParams.value = {
  261. pageNo: 1,
  262. pageSize: 10,
  263. type: null,
  264. status: null,
  265. code: '',
  266. content: '',
  267. apiTemplateId: '',
  268. channelId: null,
  269. createTime: []
  270. }
  271. queryForm.value?.resetFields()
  272. }
  273. // 短信渠道
  274. const channelOptions = ref<SmsChannelApi.SmsChannelListVO[]>([])
  275. onMounted(() => {
  276. SmsChannelApi.getSimpleSmsChannels().then((res) => {
  277. channelOptions.value = res
  278. })
  279. })
  280. const optionLabel = computed(
  281. () => (type: string, code: string) => `【${getDictLabel(type, code)}】`
  282. )
  283. /** 格式化短信渠道 */
  284. const formatChannelSignature = (channelId: number) => {
  285. channelOptions.value.forEach((item) => {
  286. if (item.id === channelId) {
  287. return item.signature
  288. }
  289. })
  290. return '找不到签名:' + channelId
  291. }
  292. /** 新增按钮操作 */
  293. const handleAdd = (type: string) => {
  294. modalRef.value.openModal({ type })
  295. }
  296. /** 修改按钮操作 */
  297. // const handleUpdate = (row) => {}
  298. const exportLoading = ref(false)
  299. /** 导出按钮操作 */
  300. const handleExport = () => {
  301. // 处理查询参数
  302. let params = { ...queryParams.value } as templateApi.SmsTemplateExportReqVO
  303. // 执行导出
  304. message
  305. .confirm('是否确认导出所有短信模板数据项?', '警告')
  306. .then(() => {
  307. exportLoading.value = true
  308. return templateApi.exportPostApi(params)
  309. })
  310. .then((response) => {
  311. download.excel(response, '短信模板.xls')
  312. exportLoading.value = false
  313. })
  314. .catch(() => {})
  315. }
  316. /** 发送短信按钮 */
  317. const handleSendSms = (type, row: any) => {
  318. modalRef.value.openModal({ type, row })
  319. }
  320. const handleUpdate = (type: string, { id }: { id: number }) => {
  321. modalRef.value.openModal({ type, id })
  322. }
  323. /** 删除按钮操作 */
  324. const handleDelete = ({ id }: { id: number }) => {
  325. message
  326. .confirm('是否确认删除短信模板编号为"' + id + '"的数据项?')
  327. .then(function () {
  328. return templateApi.deleteSmsTemplateApi(id)
  329. })
  330. .then(() => {
  331. getList()
  332. message.success('删除成功')
  333. })
  334. .catch(() => {})
  335. }
  336. getList()
  337. </script>