ListView.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div style="height: 100%">
  3. <div id="operation">
  4. <div id="action">
  5. <RouterLink to="/editer">+{{ lang.compose }}</RouterLink>
  6. </div>
  7. </div>
  8. <div id="title">{{ groupStore.name }}</div>
  9. <div id="action">
  10. <el-button @click="del" size="small">{{ lang.del_btn }}</el-button>
  11. <el-button @click="markRead" size="small">{{ lang.read_btn }}</el-button>
  12. <el-dropdown style="margin-left: 12px;">
  13. <el-button size="small">
  14. {{ lang.move_btn }}
  15. <el-icon class="el-icon--right"><arrow-down /></el-icon>
  16. </el-button>
  17. <template #dropdown>
  18. <el-dropdown-menu>
  19. <el-dropdown-item @click="move(group.id)" v-for="group in groupList">{{ group.name
  20. }}</el-dropdown-item>
  21. </el-dropdown-menu>
  22. </template>
  23. </el-dropdown>
  24. </div>
  25. <div id="table">
  26. <el-table ref="taskTableDataRef" @selection-change="selectionLineChange" :data="data" :show-header="true"
  27. :border="false" @row-click="rowClick" :row-style="rowStyle">
  28. <el-table-column type="selection" width="30" />
  29. <el-table-column prop="is_read" label="" width="50">
  30. <template #default="scope">
  31. <div>
  32. <span v-if="!scope.row.is_read">
  33. {{ lang.new }}
  34. </span>
  35. <span style="font-weight: 900;color: #FF0000;" v-if="scope.row.dangerous">
  36. <el-tooltip effect="dark" :content="lang.dangerous" placement="top-start">
  37. !
  38. </el-tooltip>
  39. </span>
  40. <span style="font-weight: 900;color: #FF0000;" v-if="scope.row.error != ''">
  41. <el-tooltip effect="dark" :content="scope.row.error" placement="top-start">
  42. !
  43. </el-tooltip>
  44. </span>
  45. </div>
  46. </template>
  47. </el-table-column>
  48. <el-table-column prop="title" :label="lang.sender" width="150">
  49. <template #default="scope">
  50. <el-tooltip class="box-item" effect="dark" :content="scope.row.sender.EmailAddress" placement="top">
  51. <el-tag size="small" type="info">{{scope.row.sender.Name != '' ? scope.row.sender.Name : scope.row.sender.EmailAddress }}</el-tag>
  52. </el-tooltip>
  53. </template>
  54. </el-table-column>
  55. <el-table-column prop="title" :label="lang.to" width="150">
  56. <template #default="scope">
  57. <el-tooltip v-for="toInfo in scope.row.to" class="box-item" effect="dark" :content="toInfo.EmailAddress" placement="top">
  58. <el-tag size="small" type="info">{{toInfo.Name != '' ? toInfo.Name : toInfo.EmailAddress }}</el-tag>
  59. </el-tooltip>
  60. </template>
  61. </el-table-column>
  62. <el-table-column prop="desc" :label="lang.title">
  63. <template #default="scope">
  64. <div v-if="scope.row.is_read">{{ scope.row.title }}</div>
  65. <div v-else style="font-weight:bolder;">{{ scope.row.title }}</div>
  66. <div style="font-size: 12px;height: 24px;">{{ scope.row.desc }}</div>
  67. </template>
  68. </el-table-column>
  69. <el-table-column prop="datetime" :label="lang.date" width="180">
  70. <template #default="scope">
  71. <span v-if="scope.row.is_read">{{ scope.row.datetime }}</span>
  72. <span v-else style="font-weight:bolder;">{{ scope.row.datetime }}</span>
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. </div>
  77. <div id="pagination">
  78. <el-pagination background layout="prev, pager, next" :page-count="totalPage" @current-change="pageChange" />
  79. </div>
  80. </div>
  81. </template>
  82. <script setup>
  83. import { ArrowDown } from '@element-plus/icons-vue'
  84. import { RouterLink } from 'vue-router'
  85. import { reactive, ref, watch } from 'vue'
  86. import useGroupStore from '../stores/group'
  87. import lang from '../i18n/i18n';
  88. import { useRouter } from 'vue-router';
  89. import { getCurrentInstance } from 'vue'
  90. const app = getCurrentInstance()
  91. const $http = app.appContext.config.globalProperties.$http
  92. const router = useRouter();
  93. const groupStore = useGroupStore()
  94. const groupList = ref([])
  95. const taskTableDataRef = ref(null)
  96. let tag = groupStore.tag;
  97. if (tag == "") {
  98. tag = '{"type":0,"status":-1}'
  99. }
  100. watch(groupStore, async (newV, oldV) => {
  101. tag = newV.tag;
  102. if (tag == "") {
  103. tag = '{"type":0,"status":-1}'
  104. }
  105. data.value = []
  106. $http.post("/api/email/list", { tag: tag, page_size: 10 }).then(res => {
  107. data.value = res.data.list
  108. totalPage.value = res.data.total_page
  109. })
  110. })
  111. const data = ref([])
  112. const totalPage = ref(0)
  113. const updateList = function () {
  114. $http.post("/api/email/list", { tag: tag, page_size: 10 }).then(res => {
  115. data.value = res.data.list
  116. totalPage.value = res.data.total_page
  117. })
  118. }
  119. const updateGroupList = function () {
  120. $http.post("/api/group/list").then(res => {
  121. groupList.value = res.data
  122. })
  123. }
  124. updateList()
  125. updateGroupList()
  126. const rowClick = function (row, column, event) {
  127. router.push("/detail/" + row.id)
  128. }
  129. const markRead = function () {
  130. let rows = taskTableDataRef.value?.getSelectionRows()
  131. let ids = []
  132. rows.forEach(element => {
  133. ids.push(element.id)
  134. });
  135. $http.post("/api/email/read", { "ids": ids }).then(res => {
  136. if (res.errorNo == 0) {
  137. updateList()
  138. } else {
  139. ElMessage({
  140. type: 'error',
  141. message: res.errorMsg,
  142. })
  143. }
  144. })
  145. }
  146. const move = function (group_id) {
  147. let rows = taskTableDataRef.value?.getSelectionRows()
  148. let ids = []
  149. rows.forEach(element => {
  150. ids.push(element.id)
  151. });
  152. ElMessageBox.confirm(
  153. lang.move_email_confirm,
  154. 'Warning',
  155. {
  156. confirmButtonText: 'OK',
  157. cancelButtonText: 'Cancel',
  158. type: 'warning',
  159. }
  160. )
  161. .then(() => {
  162. $http.post("/api/email/move", { "group_id": group_id, "ids": ids }).then(res => {
  163. if (res.errorNo == 0) {
  164. updateList()
  165. ElMessage({
  166. type: 'success',
  167. message: 'Move completed',
  168. })
  169. } else {
  170. ElMessage({
  171. type: 'error',
  172. message: res.errorMsg,
  173. })
  174. }
  175. })
  176. })
  177. }
  178. const del = function () {
  179. let rows = taskTableDataRef.value?.getSelectionRows()
  180. let ids = []
  181. rows.forEach(element => {
  182. ids.push(element.id)
  183. });
  184. let groupTag = JSON.parse(tag)
  185. ElMessageBox.confirm(
  186. lang.del_email_confirm,
  187. 'Warning',
  188. {
  189. confirmButtonText: 'OK',
  190. cancelButtonText: 'Cancel',
  191. type: 'warning',
  192. }
  193. )
  194. .then(() => {
  195. $http.post("/api/email/del", { "ids": ids ,"forcedDel":groupTag.status == 3 }).then(res => {
  196. if (res.errorNo == 0) {
  197. updateList()
  198. ElMessage({
  199. type: 'success',
  200. message: 'Delete completed',
  201. })
  202. } else {
  203. ElMessage({
  204. type: 'error',
  205. message: res.errorMsg,
  206. })
  207. }
  208. })
  209. })
  210. }
  211. const rowStyle = function ({ row, rowIndwx }) {
  212. return { 'cursor': 'pointer' }
  213. }
  214. const pageChange = function (p) {
  215. $http.post("/api/email/list", { tag: tag, page_size: 10, current_page: p }).then(res => {
  216. data.value = res.data.list
  217. })
  218. }
  219. </script>
  220. <style scoped>
  221. #action {
  222. display: flex;
  223. flex-direction: row;
  224. }
  225. #action a,
  226. a:visited {
  227. color: #000000;
  228. text-decoration: none;
  229. }
  230. #operation {
  231. display: flex;
  232. height: 40px;
  233. background-color: rgb(236, 244, 251);
  234. }
  235. #title {
  236. margin-top: 10px;
  237. font-size: 23px;
  238. text-align: left;
  239. padding-left: 20px;
  240. }
  241. #table {
  242. text-align: left;
  243. width: 100%;
  244. padding-left: 20px;
  245. }
  246. #pagination {
  247. padding-top: 30px;
  248. display: flex;
  249. justify-content: center;
  250. /* 水平居中 */
  251. width: 100%;
  252. }
  253. </style>