index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div class="tenant">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable
  6. :source="sourceList.data"
  7. :pagination="sourceList.pagination"
  8. :config="config"
  9. :loading="loading"
  10. highlight-current-row
  11. :selectConfig="selectConfig"
  12. :table-events="{
  13. //element talbe事件都能传
  14. select: select,
  15. }"
  16. :action-list="[
  17. {
  18. text: '添加邮箱',
  19. action: () => openModal('add'),
  20. },
  21. ]"
  22. @get-list="getList"
  23. >
  24. <template #slotName="{ item }">
  25. {{ item.createTime }}
  26. </template>
  27. </byTable>
  28. </div>
  29. <el-dialog
  30. :title="modalType == 'add' ? '添加邮箱' : '编辑邮箱'"
  31. v-model="dialogVisible"
  32. width="400"
  33. v-loading="loading"
  34. >
  35. <byForm
  36. :formConfig="formConfig"
  37. :formOption="formOption"
  38. v-model="formData.data"
  39. :rules="rules"
  40. ref="byform"
  41. >
  42. <template #rSlot>
  43. <el-row style="width: 100%" :gutter="15">
  44. <el-col :span="10">
  45. <el-select
  46. v-model="formData.data.receiveProtocol"
  47. placeholder="收件协议"
  48. disabled
  49. >
  50. </el-select>
  51. </el-col>
  52. <el-col :span="10">
  53. <el-input
  54. v-model="formData.data.receivePort"
  55. placeholder="请输入"
  56. >
  57. </el-input>
  58. </el-col>
  59. </el-row>
  60. </template>
  61. <template #sSlot>
  62. <el-row style="width: 100%" :gutter="15">
  63. <el-col :span="10">
  64. <el-select
  65. v-model="formData.data.sendProtocol"
  66. placeholder="发件协议"
  67. disabled
  68. >
  69. </el-select>
  70. </el-col>
  71. <el-col :span="10">
  72. <el-input v-model="formData.data.sendPort" placeholder="请输入">
  73. </el-input>
  74. </el-col>
  75. </el-row>
  76. </template>
  77. </byForm>
  78. <template #footer>
  79. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  80. <el-button
  81. type="primary"
  82. @click="submitForm('byform')"
  83. size="large"
  84. :loading="submitLoading"
  85. >
  86. 确 定
  87. </el-button>
  88. </template>
  89. </el-dialog>
  90. </div>
  91. </template>
  92. <script setup>
  93. /* eslint-disable vue/no-unused-components */
  94. import { ElMessage, ElMessageBox } from "element-plus";
  95. import byTable from "@/components/byTable/index";
  96. import byForm from "@/components/byForm/index";
  97. import { computed, defineComponent, ref } from "vue";
  98. import { validEmail } from "@/utils/validate.js";
  99. const loading = ref(false);
  100. const submitLoading = ref(false);
  101. const sourceList = ref({
  102. data: [],
  103. pagination: {
  104. total: 3,
  105. pageNum: 1,
  106. pageSize: 10,
  107. },
  108. });
  109. let dialogVisible = ref(false);
  110. let modalType = ref("add");
  111. let rules = ref({
  112. mailUser: [{ required: true, message: "请输入邮箱地址", trigger: "blur" }],
  113. type: [{ required: true, message: "请选择邮箱类型", trigger: "change" }],
  114. mailPassword: [{ required: true, message: "请输入授权码", trigger: "blur" }],
  115. receiveHost: [
  116. { required: true, message: "请输入收件服务器地址", trigger: "blur" },
  117. ],
  118. receivePort: [{ required: true, message: "请输入收件端口", trigger: "blur" }],
  119. receiveProtocol: [
  120. { required: true, message: "请输入收件协议", trigger: "blur" },
  121. ],
  122. sendHost: [
  123. { required: true, message: "请输入发件服务器地址", trigger: "blur" },
  124. ],
  125. sendPort: [{ required: true, message: "请输入发件端口", trigger: "blur" }],
  126. sendProtocol: [
  127. { required: true, message: "请输入发件协议", trigger: "blur" },
  128. ],
  129. });
  130. const { proxy } = getCurrentInstance();
  131. const selectConfig = [];
  132. const config = computed(() => {
  133. return [
  134. {
  135. attrs: {
  136. label: "邮箱地址",
  137. prop: "mailUser",
  138. },
  139. },
  140. {
  141. attrs: {
  142. label: "海外邮箱",
  143. prop: "type",
  144. },
  145. render(type) {
  146. return type == 2 ? "是" : "否";
  147. },
  148. },
  149. {
  150. attrs: {
  151. label: "授权码",
  152. prop: "mailPassword",
  153. },
  154. },
  155. {
  156. attrs: {
  157. label: "收件协议",
  158. prop: "receiveProtocol",
  159. },
  160. },
  161. {
  162. attrs: {
  163. label: "收件端口号",
  164. prop: "receivePort",
  165. },
  166. },
  167. {
  168. attrs: {
  169. label: "发件协议",
  170. prop: "sendProtocol",
  171. },
  172. },
  173. {
  174. attrs: {
  175. label: "发件端口号",
  176. prop: "sendPort",
  177. },
  178. },
  179. {
  180. attrs: {
  181. label: "操作",
  182. width: "200",
  183. align: "right",
  184. },
  185. // 渲染 el-button,一般用在最后一列。
  186. renderHTML(row) {
  187. return [
  188. {
  189. attrs: {
  190. label: "修改",
  191. type: "primary",
  192. text: true,
  193. },
  194. el: "button",
  195. click() {
  196. getDtl(row);
  197. },
  198. },
  199. {
  200. attrs: {
  201. label: "删除",
  202. type: "danger",
  203. text: true,
  204. },
  205. el: "button",
  206. click() {
  207. // 弹窗提示是否删除
  208. ElMessageBox.confirm(
  209. "此操作将永久删除该数据, 是否继续?",
  210. "提示",
  211. {
  212. confirmButtonText: "确定",
  213. cancelButtonText: "取消",
  214. type: "warning",
  215. }
  216. ).then(() => {
  217. // 删除
  218. proxy
  219. .post("/personalMailbox/delete", {
  220. id: row.id,
  221. })
  222. .then((res) => {
  223. ElMessage({
  224. message: "删除成功",
  225. type: "success",
  226. });
  227. getList();
  228. });
  229. });
  230. },
  231. },
  232. ];
  233. },
  234. },
  235. ];
  236. });
  237. let formData = reactive({
  238. data: {},
  239. });
  240. const formOption = reactive({
  241. inline: true,
  242. labelWidth: 100,
  243. itemWidth: 100,
  244. rules: [],
  245. });
  246. const byform = ref(null);
  247. const formConfig = computed(() => {
  248. return [
  249. {
  250. type: "input",
  251. prop: "mailUser",
  252. label: "邮箱地址",
  253. required: true,
  254. },
  255. {
  256. type: "radio",
  257. prop: "type",
  258. label: "是否海外邮箱",
  259. required: true,
  260. border: true,
  261. data: [
  262. { label: "是", value: "2" },
  263. { label: "否", value: "1" },
  264. ],
  265. },
  266. {
  267. type: "input",
  268. prop: "mailPassword",
  269. label: "授权码",
  270. required: true,
  271. },
  272. {
  273. type: "input",
  274. prop: "receiveHost",
  275. label: "收件服务器地址",
  276. required: true,
  277. },
  278. {
  279. type: "slot",
  280. slotName: "rSlot",
  281. prop: "receivePort",
  282. label: "收件协议",
  283. required: true,
  284. },
  285. {
  286. type: "input",
  287. prop: "sendHost",
  288. label: "发件服务器地址",
  289. required: true,
  290. },
  291. {
  292. type: "slot",
  293. slotName: "sSlot",
  294. prop: "sendPort",
  295. label: "发件协议",
  296. required: true,
  297. },
  298. ];
  299. });
  300. const getList = async (req) => {
  301. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  302. loading.value = true;
  303. proxy
  304. .post("/personalMailbox/page", sourceList.value.pagination)
  305. .then((message) => {
  306. console.log(message);
  307. sourceList.value.data = message.rows;
  308. sourceList.value.pagination.total = message.total;
  309. setTimeout(() => {
  310. loading.value = false;
  311. }, 200);
  312. });
  313. };
  314. const openModal = () => {
  315. modalType.value = "add";
  316. formData.data = {};
  317. formData.data.type = "1";
  318. formData.data.receiveProtocol = "IMAP";
  319. formData.data.sendProtocol = "SMTP";
  320. dialogVisible.value = true;
  321. };
  322. const submitForm = () => {
  323. byform.value.handleSubmit((valid) => {
  324. if (validEmail(formData.data.mailUser)) {
  325. submitLoading.value = true;
  326. proxy.post("/personalMailbox/" + modalType.value, formData.data).then(
  327. (res) => {
  328. ElMessage({
  329. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  330. type: "success",
  331. });
  332. dialogVisible.value = false;
  333. submitLoading.value = false;
  334. getList();
  335. },
  336. (err) => (submitLoading.value = false)
  337. );
  338. } else {
  339. ElMessage({
  340. message: "邮箱格式不正确!",
  341. type: "info",
  342. });
  343. }
  344. });
  345. };
  346. const getDtl = (row) => {
  347. modalType.value = "edit";
  348. proxy.post("/personalMailbox/detail", { id: row.id }).then((res) => {
  349. res.type = res.type + "";
  350. formData.data = res;
  351. dialogVisible.value = true;
  352. });
  353. };
  354. getList();
  355. </script>
  356. <style lang="scss" scoped>
  357. .tenant {
  358. padding: 20px;
  359. }
  360. </style>