|
|
@@ -1,252 +1,243 @@
|
|
|
<template>
|
|
|
- <div class="list-view">
|
|
|
- <page-title>
|
|
|
- <el-button
|
|
|
- @click="addRow"
|
|
|
- type="primary"
|
|
|
- icon="el-icon-plus"
|
|
|
- :disabled="fetchingData || downloading"
|
|
|
- class="filter-item"
|
|
|
- >
|
|
|
- 新增
|
|
|
- </el-button>
|
|
|
- <el-button
|
|
|
- @click="download"
|
|
|
- icon="el-icon-upload2"
|
|
|
- :loading="downloading"
|
|
|
- :disabled="fetchingData"
|
|
|
- class="filter-item"
|
|
|
- >
|
|
|
- 导出
|
|
|
- </el-button>
|
|
|
- </page-title>
|
|
|
- <div class="filters-container">
|
|
|
- <el-input
|
|
|
- placeholder="搜索..."
|
|
|
- v-model="search"
|
|
|
- clearable
|
|
|
- class="filter-item search"
|
|
|
- @keyup.enter.native="getData"
|
|
|
- >
|
|
|
- <el-button @click="getData" slot="append" icon="el-icon-search"> </el-button>
|
|
|
- </el-input>
|
|
|
- </div>
|
|
|
- <el-table
|
|
|
- :data="tableData"
|
|
|
- row-key="id"
|
|
|
- ref="table"
|
|
|
- header-row-class-name="table-header-row"
|
|
|
- header-cell-class-name="table-header-cell"
|
|
|
- row-class-name="table-row"
|
|
|
- cell-class-name="table-cell"
|
|
|
- :height="tableHeight"
|
|
|
- v-loading="fetchingData"
|
|
|
- >
|
|
|
- <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
|
|
|
- <el-table-column prop="id" align="center" label="ID" width="100"> </el-table-column>
|
|
|
- <el-table-column prop="title" align="center" label="邮件标题" width="200"> </el-table-column>
|
|
|
- <el-table-column prop="author" align="center" label="邮件作者" width="100"> </el-table-column>
|
|
|
- <el-table-column prop="description" align="center" label="邮件内容"> </el-table-column>
|
|
|
- <el-table-column prop="publish" align="center" label="是否发布" width="80">
|
|
|
- <template slot-scope="{ row }">
|
|
|
- <el-tag :type="row.publish ? '' : 'info'"> {{ row.publish }} </el-tag>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column label="操作" align="center" fixed="right" width="300">
|
|
|
- <template slot-scope="{ row }">
|
|
|
- <el-button @click="publish(row)" type="primary" size="mini" plain v-if="row && !row.publish">
|
|
|
- 发布
|
|
|
- </el-button>
|
|
|
- <el-button @click="editRow(row)" type="primary" size="mini" plain v-if="row && !row.publish">
|
|
|
- 编辑
|
|
|
- </el-button>
|
|
|
- <el-button @click="deleteRow(row)" type="danger" size="mini" plain v-if="row && !row.publish">
|
|
|
- 删除
|
|
|
- </el-button>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
- <div class="pagination-wrapper">
|
|
|
- <el-pagination
|
|
|
- background
|
|
|
- @size-change="onSizeChange"
|
|
|
- @current-change="onCurrentChange"
|
|
|
- :current-page="page"
|
|
|
- :page-sizes="[10, 20, 30, 40, 50]"
|
|
|
- :page-size="pageSize"
|
|
|
- layout="total, sizes, prev, pager, next, jumper"
|
|
|
- :total="totalElements"
|
|
|
- >
|
|
|
- </el-pagination>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ <div class="list-view">
|
|
|
+ <page-title>
|
|
|
+ <el-button
|
|
|
+ @click="addRow"
|
|
|
+ type="primary"
|
|
|
+ icon="el-icon-plus"
|
|
|
+ :disabled="fetchingData || downloading"
|
|
|
+ class="filter-item"
|
|
|
+ >
|
|
|
+ 新增
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ @click="download"
|
|
|
+ icon="el-icon-upload2"
|
|
|
+ :loading="downloading"
|
|
|
+ :disabled="fetchingData"
|
|
|
+ class="filter-item"
|
|
|
+ >
|
|
|
+ 导出
|
|
|
+ </el-button>
|
|
|
+ </page-title>
|
|
|
+ <div class="filters-container">
|
|
|
+ <el-input
|
|
|
+ placeholder="搜索..."
|
|
|
+ v-model="search"
|
|
|
+ clearable
|
|
|
+ class="filter-item search"
|
|
|
+ @keyup.enter.native="getData"
|
|
|
+ >
|
|
|
+ <el-button @click="getData" slot="append" icon="el-icon-search"> </el-button>
|
|
|
+ </el-input>
|
|
|
+ </div>
|
|
|
+ <el-table
|
|
|
+ :data="tableData"
|
|
|
+ row-key="id"
|
|
|
+ ref="table"
|
|
|
+ header-row-class-name="table-header-row"
|
|
|
+ header-cell-class-name="table-header-cell"
|
|
|
+ row-class-name="table-row"
|
|
|
+ cell-class-name="table-cell"
|
|
|
+ :height="tableHeight"
|
|
|
+ v-loading="fetchingData"
|
|
|
+ >
|
|
|
+ <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
|
|
|
+ <el-table-column prop="id" align="center" label="ID" width="100"> </el-table-column>
|
|
|
+ <el-table-column prop="title" align="center" label="邮件标题" width="200"> </el-table-column>
|
|
|
+ <el-table-column prop="author" align="center" label="邮件作者" width="100"> </el-table-column>
|
|
|
+ <el-table-column prop="description" align="center" label="邮件内容"> </el-table-column>
|
|
|
+ <el-table-column prop="publish" align="center" label="是否发布" width="80">
|
|
|
+ <template slot-scope="{ row }">
|
|
|
+ <el-tag :type="row.publish ? '' : 'info'"> {{ row.publish }} </el-tag>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" align="center" fixed="right" width="300">
|
|
|
+ <template slot-scope="{ row }">
|
|
|
+ <el-button @click="publish(row)" type="primary" size="mini" plain v-if="row && !row.publish">
|
|
|
+ 发布
|
|
|
+ </el-button>
|
|
|
+ <el-button @click="editRow(row)" type="primary" size="mini" plain v-if="row && !row.publish">
|
|
|
+ 编辑
|
|
|
+ </el-button>
|
|
|
+ <el-button @click="deleteRow(row)" type="danger" size="mini" plain v-if="row && !row.publish">
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <div class="pagination-wrapper">
|
|
|
+ <el-pagination
|
|
|
+ background
|
|
|
+ @size-change="onSizeChange"
|
|
|
+ @current-change="onCurrentChange"
|
|
|
+ :current-page="page"
|
|
|
+ :page-sizes="[10, 20, 30, 40, 50]"
|
|
|
+ :page-size="pageSize"
|
|
|
+ layout="total, sizes, prev, pager, next, jumper"
|
|
|
+ :total="totalElements"
|
|
|
+ >
|
|
|
+ </el-pagination>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
<script>
|
|
|
import { mapState } from 'vuex';
|
|
|
import pageableTable from '@/mixins/pageableTable';
|
|
|
|
|
|
export default {
|
|
|
- name: 'MetaEmailList',
|
|
|
- mixins: [pageableTable],
|
|
|
- data() {
|
|
|
- return {
|
|
|
- connected: false,
|
|
|
- timer: null,
|
|
|
- websock: null,
|
|
|
- multipleMode: false,
|
|
|
- search: '',
|
|
|
- url: '/metaEmail/all',
|
|
|
- downloading: false
|
|
|
- };
|
|
|
- },
|
|
|
- created() {
|
|
|
- // 初始化websocket
|
|
|
- this.initWebSocket();
|
|
|
- },
|
|
|
- destroyed() {
|
|
|
- window.clearInterval(this.timer);
|
|
|
- //离开路由之后断开websocket连接
|
|
|
- this.websock.close();
|
|
|
- },
|
|
|
- computed: {
|
|
|
- selection() {
|
|
|
- return this.$refs.table.selection.map(i => i.id);
|
|
|
- }
|
|
|
- },
|
|
|
- methods: {
|
|
|
- beforeGetData() {
|
|
|
- return { search: this.search, query: { del: false } };
|
|
|
- },
|
|
|
- toggleMultipleMode(multipleMode) {
|
|
|
- this.multipleMode = multipleMode;
|
|
|
- if (!multipleMode) {
|
|
|
- this.$refs.table.clearSelection();
|
|
|
- }
|
|
|
- },
|
|
|
- addRow() {
|
|
|
- this.$router.push({
|
|
|
- path: '/metaEmailEdit',
|
|
|
- query: {
|
|
|
- ...this.$route.query
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- editRow(row) {
|
|
|
- this.$router.push({
|
|
|
- path: '/metaEmailEdit',
|
|
|
- query: {
|
|
|
- id: row.id
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- download() {
|
|
|
- this.downloading = true;
|
|
|
- this.$axios
|
|
|
- .get('/metaEmail/excel', {
|
|
|
- responseType: 'blob',
|
|
|
- params: { size: 10000 }
|
|
|
- })
|
|
|
- .then(res => {
|
|
|
- console.log(res);
|
|
|
- this.downloading = false;
|
|
|
- const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
|
|
|
- const link = document.createElement('a');
|
|
|
- link.href = downloadUrl;
|
|
|
- link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
|
|
|
- document.body.appendChild(link);
|
|
|
- link.click();
|
|
|
- link.remove();
|
|
|
- })
|
|
|
- .catch(e => {
|
|
|
- console.log(e);
|
|
|
- this.downloading = false;
|
|
|
- this.$message.error(e.error);
|
|
|
- });
|
|
|
- },
|
|
|
- deleteRow(row) {
|
|
|
- this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
|
|
|
- .then(() => {
|
|
|
- return this.$http.post(`/metaEmail/del/${row.id}`);
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- this.$message.success('删除成功');
|
|
|
- this.getData();
|
|
|
- })
|
|
|
- .catch(e => {
|
|
|
- if (e !== 'cancel') {
|
|
|
- this.$message.error(e.error);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- publish(row) {
|
|
|
- if (!this.connected) {
|
|
|
- this.$message.error('当前socket连接异常');
|
|
|
- return;
|
|
|
- }
|
|
|
- this.$alert('邮件发布之后不能编辑和删除,请确定是否发布邮件!', '提示', { type: 'info' })
|
|
|
- .then(() => {
|
|
|
- this.$http.post(`/metaEmail/${row.id}/publish`);
|
|
|
- this.websocketsend(JSON.stringify({ type: 'META_WEBSOCKET_NOTICE_EMAIL_NOTICE' }));
|
|
|
- return;
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- setTimeout(() => {
|
|
|
- this.$message.success('发布成功');
|
|
|
- this.getData();
|
|
|
- }, 1000);
|
|
|
- })
|
|
|
- .catch(e => {
|
|
|
- if (e !== 'cancel') {
|
|
|
- this.$message.error(e.error);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- initWebSocket() {
|
|
|
- let wsuri = 'ws://127.0.0.1:8088/websocket/' + this.$store.state.userInfo.id;
|
|
|
- if (location.host === 'raex.vip') {
|
|
|
- wsuri = 'wss://mmo.raex.vip/websocket/' + this.$store.state.userInfo.id;
|
|
|
- }
|
|
|
- if (location.host === 'test.raex.vip') {
|
|
|
- wsuri = 'wss://test.mmo.raex.vip/websocket/' + this.$store.state.userInfo.id;
|
|
|
- }
|
|
|
- console.log('初始化websocket:' + wsuri);
|
|
|
- this.websock = new WebSocket(wsuri);
|
|
|
- this.websock.onmessage = this.websocketonmessage;
|
|
|
- this.websock.onopen = this.websocketonopen;
|
|
|
- this.websock.onerror = this.websocketonerror;
|
|
|
- this.websock.onclose = this.websocketclose;
|
|
|
- },
|
|
|
- websocketonopen() {
|
|
|
- this.websocketsend('META_PING');
|
|
|
- this.timer = window.setInterval(() => {
|
|
|
- setTimeout(() => {
|
|
|
- this.websocketsend('META_PING');
|
|
|
- }, 0);
|
|
|
- }, 10000);
|
|
|
- },
|
|
|
- websocketonerror() {
|
|
|
- this.connected = false;
|
|
|
- console.log('socket连接异常');
|
|
|
- this.initWebSocket();
|
|
|
- },
|
|
|
- websocketonmessage(e) {
|
|
|
- console.log('socket接收数据:' + e.data);
|
|
|
- if (e.data === 'META_PONG') {
|
|
|
- this.connected = true;
|
|
|
- return;
|
|
|
- }
|
|
|
- this.connected = false;
|
|
|
- this.initWebSocket();
|
|
|
- },
|
|
|
- websocketsend(Data) {
|
|
|
- console.log('socket发送数据:' + Data);
|
|
|
- this.websock.send(Data);
|
|
|
- },
|
|
|
- websocketclose(e) {
|
|
|
- this.connected = false;
|
|
|
- console.log('socket断开连接:', e);
|
|
|
- }
|
|
|
- }
|
|
|
+ name: 'MetaEmailList',
|
|
|
+ mixins: [pageableTable],
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ timer: null,
|
|
|
+ websock: null,
|
|
|
+ multipleMode: false,
|
|
|
+ search: '',
|
|
|
+ url: '/metaEmail/all',
|
|
|
+ downloading: false
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ // 初始化websocket
|
|
|
+ this.initWebSocket();
|
|
|
+ },
|
|
|
+ destroyed() {
|
|
|
+ window.clearInterval(this.timer);
|
|
|
+ //离开路由之后断开websocket连接
|
|
|
+ this.websock.close();
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ selection() {
|
|
|
+ return this.$refs.table.selection.map(i => i.id);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ beforeGetData() {
|
|
|
+ return { search: this.search, query: { del: false } };
|
|
|
+ },
|
|
|
+ toggleMultipleMode(multipleMode) {
|
|
|
+ this.multipleMode = multipleMode;
|
|
|
+ if (!multipleMode) {
|
|
|
+ this.$refs.table.clearSelection();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ addRow() {
|
|
|
+ this.$router.push({
|
|
|
+ path: '/metaEmailEdit',
|
|
|
+ query: {
|
|
|
+ ...this.$route.query
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ editRow(row) {
|
|
|
+ this.$router.push({
|
|
|
+ path: '/metaEmailEdit',
|
|
|
+ query: {
|
|
|
+ id: row.id
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ download() {
|
|
|
+ this.downloading = true;
|
|
|
+ this.$axios
|
|
|
+ .get('/metaEmail/excel', {
|
|
|
+ responseType: 'blob',
|
|
|
+ params: { size: 10000 }
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ console.log(res);
|
|
|
+ this.downloading = false;
|
|
|
+ const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.href = downloadUrl;
|
|
|
+ link.setAttribute('download', res.headers['content-disposition'].split('filename=')[1]);
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ link.remove();
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ console.log(e);
|
|
|
+ this.downloading = false;
|
|
|
+ this.$message.error(e.error);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ deleteRow(row) {
|
|
|
+ this.$alert('删除将无法恢复,确认要删除么?', '警告', { type: 'error' })
|
|
|
+ .then(() => {
|
|
|
+ return this.$http.post(`/metaEmail/del/${row.id}`);
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ this.$message.success('删除成功');
|
|
|
+ this.getData();
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ if (e !== 'cancel') {
|
|
|
+ this.$message.error(e.error);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ publish(row) {
|
|
|
+ if (!this.websock.readyState === 1) {
|
|
|
+ this.$message.error('当前socket连接异常,请刷新页面重试!');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.$alert('邮件发布之后不能编辑和删除,请确定是否发布邮件!', '提示', { type: 'info' })
|
|
|
+ .then(() => {
|
|
|
+ this.$http.post(`/metaEmail/${row.id}/publish`);
|
|
|
+ this.websocketsend(JSON.stringify({ type: 'META_WEBSOCKET_NOTICE_EMAIL_NOTICE' }));
|
|
|
+ return;
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.$message.success('发布成功');
|
|
|
+ this.getData();
|
|
|
+ }, 1000);
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ if (e !== 'cancel') {
|
|
|
+ this.$message.error(e.error);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ initWebSocket() {
|
|
|
+ let wsuri = 'ws://127.0.0.1:8088/websocket/' + this.$store.state.userInfo.id;
|
|
|
+ if (location.host === 'raex.vip') {
|
|
|
+ wsuri = 'wss://mmo.raex.vip/websocket/' + this.$store.state.userInfo.id;
|
|
|
+ }
|
|
|
+ if (location.host === 'test.raex.vip') {
|
|
|
+ wsuri = 'wss://test.mmo.raex.vip/websocket/' + this.$store.state.userInfo.id;
|
|
|
+ }
|
|
|
+ console.log('初始化websocket:' + wsuri);
|
|
|
+ this.websock = new WebSocket(wsuri);
|
|
|
+ this.websock.onmessage = this.websocketonmessage;
|
|
|
+ this.websock.onopen = this.websocketonopen;
|
|
|
+ this.websock.onerror = this.websocketonerror;
|
|
|
+ this.websock.onclose = this.websocketclose;
|
|
|
+ },
|
|
|
+ websocketonopen() {
|
|
|
+ this.websocketsend('META_PING');
|
|
|
+ this.timer = window.setInterval(() => {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.websocketsend('META_PING');
|
|
|
+ }, 0);
|
|
|
+ }, 10000);
|
|
|
+ },
|
|
|
+ websocketonerror() {
|
|
|
+ console.log('socket连接异常');
|
|
|
+ this.initWebSocket();
|
|
|
+ },
|
|
|
+ websocketonmessage(e) {
|
|
|
+ console.log('socket接收数据:' + e.data);
|
|
|
+ },
|
|
|
+ websocketsend(Data) {
|
|
|
+ console.log('socket发送数据:' + Data);
|
|
|
+ this.websock.send(Data);
|
|
|
+ },
|
|
|
+ websocketclose(e) {
|
|
|
+ console.log('socket断开连接:', e);
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
</script>
|
|
|
<style lang="less" scoped>
|