ListView.vue 8.1 KB

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