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 +
  55. '【' +
  56. getDictObj(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE, channel.code) +
  57. '】'
  58. "
  59. />
  60. </el-select>
  61. </el-form-item>
  62. <el-form-item label="创建时间" prop="createTime">
  63. <el-date-picker
  64. v-model="queryParams.createTime"
  65. style="width: 240px"
  66. value-format="yyyy-MM-dd HH:mm:ss"
  67. type="daterange"
  68. range-separator="-"
  69. start-placeholder="开始日期"
  70. end-placeholder="结束日期"
  71. :default-time="['00:00:00', '23:59:59']"
  72. />
  73. </el-form-item>
  74. <el-form-item>
  75. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  76. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  77. </el-form-item>
  78. </el-form>
  79. <!-- 操作工具栏 -->
  80. <el-row>
  81. <el-col :span="12">
  82. <el-row :gutter="10">
  83. <el-col :span="1.5">
  84. <el-button
  85. type="primary"
  86. plain
  87. @click="handleAdd('template.addTitle')"
  88. v-hasPermi="['system:sms-template:create']"
  89. ><Icon icon="ep:plus" class="mr-5px" />新增</el-button
  90. >
  91. </el-col>
  92. <el-col :span="1.5">
  93. <el-button
  94. type="success"
  95. plain
  96. @click="handleExport"
  97. :loading="exportLoading"
  98. v-hasPermi="['system:sms-template:export']"
  99. >
  100. <Icon icon="ep:download" class="mr-5px" /> 导出
  101. </el-button>
  102. </el-col>
  103. </el-row>
  104. </el-col>
  105. <el-col :span="12">
  106. <right-toolbar v-model:showSearch="showSearch" @query-table="getList" />
  107. </el-col>
  108. </el-row>
  109. <!-- 列表 -->
  110. <el-table v-loading="loading" :data="templateList" align="center">
  111. <el-table-column
  112. label="模板编码"
  113. align="center"
  114. prop="code"
  115. width="120"
  116. :show-overflow-tooltip="true"
  117. />
  118. <el-table-column
  119. label="模板名称"
  120. align="center"
  121. prop="name"
  122. width="120"
  123. :show-overflow-tooltip="true"
  124. />
  125. <el-table-column
  126. label="模板内容"
  127. align="center"
  128. prop="content"
  129. width="200"
  130. :show-overflow-tooltip="true"
  131. />
  132. <el-table-column label="短信类型" align="center" prop="type">
  133. <template #default="scope">
  134. <dict-tag :type="DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE" :value="scope.row.type" />
  135. </template>
  136. </el-table-column>
  137. <el-table-column label="状态" align="center" prop="status" width="80">
  138. <template #default="scope">
  139. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  140. </template>
  141. </el-table-column>
  142. <el-table-column label="备注" align="center" prop="remark" />
  143. <el-table-column
  144. label="短信 API 的模板编号"
  145. align="center"
  146. prop="apiTemplateId"
  147. width="200"
  148. :show-overflow-tooltip="true"
  149. />
  150. <el-table-column label="短信渠道" align="center" width="120">
  151. <template #default="scope">
  152. <div>{{ formatChannelSignature(scope.row.channelId) }}</div>
  153. <dict-tag :type="DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE" :value="scope.row.channelCode" />
  154. </template>
  155. </el-table-column>
  156. <el-table-column
  157. label="创建时间"
  158. align="center"
  159. prop="createTime"
  160. width="180"
  161. :formatter="dateFormatter"
  162. />
  163. <el-table-column
  164. label="操作"
  165. align="center"
  166. class-name="small-padding fixed-width"
  167. width="210"
  168. fixed="right"
  169. >
  170. <template #default="scope">
  171. <el-button
  172. link
  173. type="primary"
  174. @click="handleSendSms('template.sendSms', scope.row)"
  175. v-hasPermi="['system:sms-template:send-sms']"
  176. ><Icon icon="ep:share" class="mr-3px" />测试</el-button
  177. >
  178. <el-button
  179. link
  180. type="primary"
  181. @click="handleUpdate('template.updtaeTitle', scope.row)"
  182. v-hasPermi="['system:sms-template:update']"
  183. ><Icon icon="ep:edit" class="mr-3px" />修改</el-button
  184. >
  185. <el-button
  186. link
  187. type="primary"
  188. @click="handleDelete(scope.row)"
  189. v-hasPermi="['system:sms-template:delete']"
  190. ><Icon icon="ep:delete" class="mr-3px" />删除</el-button
  191. >
  192. </template>
  193. </el-table-column>
  194. </el-table>
  195. <!-- 分页 -->
  196. <Pagination
  197. :total="total"
  198. v-model:page="queryParams.pageNo"
  199. v-model:limit="queryParams.pageSize"
  200. @pagination="getList"
  201. />
  202. </content-wrap>
  203. <!-- 表单弹窗:添加/修改 -->
  204. <SmsTemplateFrom ref="modalRef" :channelOptions="channelOptions" @success="getList" />
  205. </template>
  206. <script setup lang="ts" name="SmsTemplate">
  207. import { DICT_TYPE, getDictOptions, getDictObj } from '@/utils/dict'
  208. import { dateFormatter } from '@/utils/formatTime'
  209. import * as templateApi from '@/api/system/sms/smsTemplate'
  210. import * as SmsChannelApi from '@/api/system/sms/smsChannel'
  211. import download from '@/utils/download'
  212. import SmsTemplateFrom from './form.vue'
  213. const message = useMessage() // 消息弹窗
  214. // const { t } = useI18n() // 国际化
  215. // 弹出层ref
  216. const modalRef = ref()
  217. // 遮罩层
  218. const loading = ref(true)
  219. // 导出遮罩层
  220. // const exportLoading = ref(false)
  221. // 显示搜索条件
  222. const showSearch = ref(true)
  223. // 表单ref
  224. const queryForm = ref()
  225. // 查询参数
  226. const queryParams = ref<templateApi.SmsTemplatePageReqVO>({
  227. pageNo: 1,
  228. pageSize: 10,
  229. type: null,
  230. status: null,
  231. code: '',
  232. content: '',
  233. apiTemplateId: '',
  234. channelId: null,
  235. createTime: []
  236. })
  237. // 总条数
  238. const total = ref(0)
  239. // 短信模板列表
  240. const templateList = ref([])
  241. /** 查询列表 */
  242. const getList = () => {
  243. loading.value = true
  244. // 执行查询
  245. templateApi.getSmsTemplatePageApi(queryParams.value).then((response) => {
  246. templateList.value = response.list
  247. total.value = response.total
  248. loading.value = false
  249. })
  250. }
  251. /** 搜索按钮操作 */
  252. const handleQuery = () => {
  253. queryParams.value.pageNo = 1
  254. getList()
  255. }
  256. /** 重置按钮操作 */
  257. const resetQuery = () => {
  258. resetForm()
  259. handleQuery()
  260. }
  261. /** 重置搜索表单 */
  262. const resetForm = () => {
  263. queryParams.value = {
  264. pageNo: 1,
  265. pageSize: 10,
  266. type: null,
  267. status: null,
  268. code: '',
  269. content: '',
  270. apiTemplateId: '',
  271. channelId: null,
  272. createTime: []
  273. }
  274. queryForm.value?.resetFields()
  275. }
  276. // 短信渠道
  277. const channelOptions = ref<SmsChannelApi.SmsChannelListVO[]>([])
  278. onMounted(() => {
  279. SmsChannelApi.getSimpleSmsChannels().then((res) => {
  280. channelOptions.value = res
  281. })
  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>