ListView.vue 8.7 KB

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