list.vue
6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<template>
<layout-page>
<i-breadcrumb slot="breadcrumb">
<i-breadcrumb-item>首页</i-breadcrumb-item>
<i-breadcrumb-item>店铺列表</i-breadcrumb-item>
</i-breadcrumb>
<layout-content-card>
<p slot="title">店铺列表</p>
<i-radio-group v-model="env" slot="extra">
<i-radio label="develop">
<span>测试环境</span>
</i-radio>
<i-radio label="production">
<span>线上环境</span>
</i-radio>
</i-radio-group>
<div class="buttons">
<i-button icon="plus" type="default" @click="onBindUrl">获取授权链接</i-button>
<i-button icon="upload" type="primary" @click="onAddToTemplate">草稿箱添加到模板</i-button>
</div>
<div class="tables">
<i-table :columns="columns" :data="eshop.eshops"></i-table>
</div>
<div class="buttons">
<i-button icon="upload" type="primary" @click="onBatchCommit">批量上传代码</i-button>
<!-- <i-button icon="pull-request" type="warning" @click="onBindUrl">批量提交审核</i-button>
<i-button icon="cloud" type="error" @click="onBindUrl">批量发布</i-button> -->
</div>
</layout-content-card>
<modal-commit ref="modalCommit"></modal-commit>
<modal-category ref="modalCategory" @on-success="onSubmitSuccess"></modal-category>
<modal-preview ref="modalPreview"></modal-preview>
<modal-add-template ref="modalAddTemplate"></modal-add-template>
<modal-upload-draft ref="modalUploadDraft"></modal-upload-draft>
</layout-page>
</template>
<script>
import {mapState} from 'vuex';
import {Button} from 'iview';
import components from './components';
export default {
name: 'EshopList',
computed: {
...mapState(['eshop']),
env: {
get() {
return this.eshop.env;
},
set(env) {
this.$store.commit('eshop/SET_ENV_CHANGE', {env});
this.fetchData();
}
}
},
data() {
return {
authType: '',
columns: [{
title: 'appId',
key: 'authAppId'
}, {
title: '店铺ID',
key: 'brandId'
}, {
title: '店铺名',
key: 'brandName'
}, {
title: '审核状态',
key: 'auditStatus'
}, {
title: '操作',
width: 270,
render: (h, {row}) => {
return (
<div class="op-btns">
<i-button icon="upload" type="primary" onClick={() => this.commit(row)}>上传代码</i-button>
<i-button icon="qr-scanner" type="success" onClick={() => this.preview(row)}>体验版</i-button>
<i-button icon="pull-request" type={row._submitAudit ? 'default' : 'warning'} onClick={() => this.submitAudit(row)}>
{row._submitAudit ? '已提交审核' : '提交审核'}
</i-button>
<i-button icon="cloud" type={row._released ? 'default' : 'error'} onClick={() => this.release(row)}>
{row._released ? '已发布' : '发布'}
</i-button>
</div>
);
}
}],
data: [],
};
},
created() {
this.fetchData();
},
methods: {
fetchData() {
this.$store.dispatch('eshop/fetchEshops');
},
preview(row) {
this.$refs.modalPreview.show(row);
},
commit(row) {
this.$refs.modalCommit.show([row]);
},
onBatchCommit() {
this.$refs.modalCommit.show(this.eshop.eshops);
},
submitAudit(row) {
this.$refs.modalCategory.show(row);
},
onSubmitSuccess(success) {
this.$store.commit('eshop/SET_SHOP_SUBMITAUDITED', {success});
},
async release(row) {
this.$Loading.start();
const result = await this.$store.dispatch('eshop/fetchWxGetVersion', row);
this.$Loading.finish();
if (result && result.errcode === 0) {
this.$Modal.confirm({
title: '确认',
content: `当前店铺"${row.brandName}"小程序版本:${result.now_version} 确认发布?`,
onOk: async() => {
const resultDomains = await this.$store.dispatch('eshop/modifyDomains', row);
if (resultDomains && resultDomains.errcode !== 0) {
return this.$Message.error(resultDomains.errmsg);
}
const setWebviewDomains = await this.$store.dispatch('eshop/setWebviewDomains', row);
if (setWebviewDomains && setWebviewDomains.errcode !== 0) {
return this.$Message.error(setWebviewDomains.errmsg);
}
const resultRelease = await this.$store.dispatch('eshop/fetchWxRelease', row);
if (resultRelease && resultRelease.errcode === 0) {
this.$Message.success('发布成功');
this.$store.commit('eshop/SET_SHOP_RELEASED', {success: [row]});
} else {
this.$Message.warning(resultRelease && resultRelease.errmsg || '');
}
}
});
} else {
this.$Message.warning(result && result.errmsg || '');
}
},
async onBindUrl() {
this.$Loading.start();
const result = await this.$store.dispatch('eshop/fetchAuthUrl');
this.$Loading.finish();
if (result && result.code === 200) {
this.$Modal.info({
title: '授权链接',
render: () => {
return (
<div style="word-wrap: break-word; margin-top: 20px;">
<a href={result.data}>点击跳转到扫码授权页面</a>
</div>
);
}
});
} else {
this.$Message.warning(result && result.message || '');
}
},
onUploadDraft() {
this.$refs.modalUploadDraft.show();
},
onAddToTemplate() {
this.$refs.modalAddTemplate.show();
}
},
components: {Button, ...components}
};
</script>
<style lang="scss">
.buttons,
.tables {
margin-bottom: 20px;
}
.op-btns {
overflow: hidden;
margin-top: 10px;
.ivu-btn {
float: left;
display: block;
margin-left: 10px;
margin-bottom: 10px;
width: 100px;
}
}
</style>