index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <!--
  2. MIT License
  3. Copyright (c) 2020 www.joolun.com
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. 芋道源码:
  20. ① 移除 avue 框架,使用 element-ui 重写
  21. -->
  22. <template>
  23. <div class="app-container">
  24. <!-- 搜索工作栏 -->
  25. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  26. <el-form-item label="公众号" prop="accountId">
  27. <el-select v-model="queryParams.accountId" placeholder="请选择公众号">
  28. <el-option v-for="item in accounts" :key="parseInt(item.id)" :label="item.name" :value="parseInt(item.id)" />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  33. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  34. </el-form-item>
  35. </el-form>
  36. <!-- tab 切换 -->
  37. <el-tabs v-model="type" @tab-click="handleClick">
  38. <!-- 操作工具栏 -->
  39. <el-row :gutter="10" class="mb8">
  40. <el-col :span="1.5">
  41. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  42. v-hasPermi="['mp:auto-reply:create']" v-if="list.length <= 0">新增
  43. </el-button>
  44. </el-col>
  45. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  46. </el-row>
  47. <!-- 列表 -->
  48. <el-tab-pane name="1">
  49. <span slot="label"><i class="el-icon-star-off"></i> 关注时回复</span>
  50. <el-table v-loading="loading" :data="list">
  51. <el-table-column label="编号" align="center" prop="id"/>
  52. <el-table-column label="回复消息类型" align="center" prop="responseMessageType"/>
  53. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  54. <template slot-scope="scope">
  55. <span>{{ parseTime(scope.row.createTime) }}</span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  59. <template slot-scope="scope">
  60. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  61. v-hasPermi="['mp:auto-reply:update']">修改
  62. </el-button>
  63. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  64. v-hasPermi="['mp:auto-reply:delete']">删除
  65. </el-button>
  66. </template>
  67. </el-table-column>
  68. </el-table>
  69. </el-tab-pane>
  70. <el-tab-pane name="2">
  71. <span slot="label"><i class="el-icon-chat-line-round"></i> 消息回复</span>
  72. <el-table v-loading="loading" :data="list">
  73. <el-table-column label="编号" align="center" prop="id"/>
  74. <el-table-column label="请求消息类型" align="center" prop="requestMessageType"/>
  75. <el-table-column label="回复消息类型" align="center" prop="responseMessageType"/>
  76. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  77. <template slot-scope="scope">
  78. <span>{{ parseTime(scope.row.createTime) }}</span>
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  82. <template slot-scope="scope">
  83. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  84. v-hasPermi="['mp:auto-reply:update']">修改
  85. </el-button>
  86. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  87. v-hasPermi="['mp:auto-reply:delete']">删除
  88. </el-button>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. </el-tab-pane>
  93. <el-tab-pane name="3">
  94. <span slot="label"><i class="el-icon-news"></i> 关键词回复</span>
  95. <el-table v-loading="loading" :data="list">
  96. <el-table-column label="编号" align="center" prop="id"/>
  97. <el-table-column label="关键词" align="center" prop="requestKeyword"/>
  98. <el-table-column label="匹配类型" align="center" prop="requestMatch"/>
  99. <el-table-column label="回复消息类型" align="center" prop="responseMessageType"/>
  100. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  101. <template slot-scope="scope">
  102. <span>{{ parseTime(scope.row.createTime) }}</span>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  106. <template slot-scope="scope">
  107. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  108. v-hasPermi="['mp:auto-reply:update']">修改
  109. </el-button>
  110. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  111. v-hasPermi="['mp:auto-reply:delete']">删除
  112. </el-button>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. </el-tab-pane>
  117. </el-tabs>
  118. <el-dialog :title="handleType === 'add' ? '新增回复消息' : '修改回复消息'" :visible.sync="dialog1Visible" width="50%">
  119. <el-form label-width="100px">
  120. <el-form-item label="请求消息类型" v-if="type == '2'">
  121. <el-select v-model="objData.reqType" placeholder="请选择">
  122. <el-option
  123. v-for="item in dictData.get('wx_req_type')"
  124. :key="item.value"
  125. :label="item.label"
  126. :value="item.value"
  127. :disabled="item.disabled"
  128. v-if="item.value !== 'event'">
  129. </el-option>
  130. </el-select>
  131. </el-form-item>
  132. <el-form-item label="匹配类型" v-if="type === '3'">
  133. <el-select v-model="objData.repMate" placeholder="请选择" style="width: 100px">
  134. <el-option
  135. v-for="item in dictData.get('wx_rep_mate')"
  136. :key="item.value"
  137. :label="item.label"
  138. :value="item.value">
  139. </el-option>
  140. </el-select>
  141. </el-form-item>
  142. <el-form-item label="关键词" v-if="type === '3'">
  143. <el-input placeholder="请输入内容" v-model="objData.reqKey" clearable> </el-input>
  144. </el-form-item>
  145. <el-form-item label="回复消息">
  146. <WxReplySelect :objData="objData" v-if="hackResetWxReplySelect"></WxReplySelect>
  147. </el-form-item>
  148. </el-form>
  149. <span slot="footer" class="dialog-footer">
  150. <el-button @click="dialog1Visible = false">取 消</el-button>
  151. <el-button type="primary" @click="handleSubmit">确 定</el-button>
  152. </span>
  153. </el-dialog>
  154. </div>
  155. </template>
  156. <script>
  157. // import { getPage, getObj, addObj, putObj, delObj } from '@/api/wxmp/wxautoreply'
  158. // import { tableOption1, tableOption2, tableOption3 } from '@/const/crud/wxmp/wxautoreply'
  159. import WxReplySelect from '@/views/mp/components/wx-reply/main.vue'
  160. import { getSimpleAccounts } from "@/api/mp/account";
  161. import { getTagPage } from "@/api/mp/tag";
  162. export default {
  163. name: 'mpAutoReply',
  164. components: {
  165. WxReplySelect
  166. },
  167. data() {
  168. return {
  169. // tab 类型(1、关注时回复;2、消息回复;3、关键词回复)
  170. type:'1',
  171. // 遮罩层
  172. loading: true,
  173. // 显示搜索条件
  174. showSearch: true,
  175. // 总条数
  176. total: 0,
  177. // 自动回复列表
  178. list: [],
  179. // 查询参数
  180. queryParams: {
  181. pageNo: 1,
  182. pageSize: 10,
  183. accountId: undefined,
  184. },
  185. dialog1Visible:false,
  186. objData:{
  187. repType : 'text'
  188. },
  189. handleType: null,
  190. dictData: new Map(),
  191. hackResetWxReplySelect: false,
  192. // 公众号账号列表
  193. accounts: []
  194. }
  195. },
  196. created() {
  197. getSimpleAccounts().then(response => {
  198. this.accounts = response.data;
  199. // 默认选中第一个
  200. if (this.accounts.length > 0) {
  201. this.queryParams.accountId = this.accounts[0].id;
  202. }
  203. // 加载数据
  204. this.getList();
  205. })
  206. // this.getPage(this.page)
  207. this.dictData.set('wx_rep_mate',[{
  208. value: '1',
  209. label: '全匹配'
  210. },{
  211. value: '2',
  212. label: '半匹配'
  213. }])
  214. this.dictData.set('wx_req_type',[{
  215. value: 'text',
  216. label: '文本'
  217. },{
  218. value: 'image',
  219. label: '图片'
  220. },{
  221. value: 'voice',
  222. label: '语音'
  223. },{
  224. value: 'video',
  225. label: '视频'
  226. },{
  227. value: 'shortvideo',
  228. label: '小视频'
  229. },{
  230. value: 'location',
  231. label: '地理位置'
  232. },{
  233. value: 'link',
  234. label: '链接消息'
  235. },{
  236. value: 'event',
  237. label: '事件推送'
  238. }])
  239. },
  240. methods: {
  241. /** 查询列表 */
  242. getList() {
  243. // 如果没有选中公众号账号,则进行提示。
  244. if (!this.queryParams.accountId) {
  245. this.$message.error('未选中公众号,无法查询标签')
  246. return false
  247. }
  248. this.loading = false
  249. // 处理查询参数
  250. let params = {...this.queryParams}
  251. // 执行查询
  252. getTagPage(params).then(response => {
  253. this.list = response.data.list
  254. this.total = response.data.total
  255. this.loading = false
  256. })
  257. },
  258. /** 搜索按钮操作 */
  259. handleQuery() {
  260. this.queryParams.pageNo = 1
  261. this.getList()
  262. },
  263. /** 重置按钮操作 */
  264. resetQuery() {
  265. this.resetForm('queryForm')
  266. // 默认选中第一个
  267. if (this.accounts.length > 0) {
  268. this.queryParams.accountId = this.accounts[0].id;
  269. }
  270. this.handleQuery()
  271. },
  272. handleAdd(){
  273. this.hackResetWxReplySelect = false//销毁组件
  274. this.$nextTick(() => {
  275. this.hackResetWxReplySelect = true//重建组件
  276. })
  277. this.handleType = 'add'
  278. this.dialog1Visible = true
  279. this.objData = {
  280. repType : 'text'
  281. }
  282. },
  283. handleEdit(row){
  284. this.hackResetWxReplySelect = false//销毁组件
  285. this.$nextTick(() => {
  286. this.hackResetWxReplySelect = true//重建组件
  287. })
  288. this.handleType = 'edit'
  289. this.dialog1Visible = true
  290. this.objData = Object.assign({}, row)
  291. },
  292. handleClick(tab, event){
  293. this.tableData = []
  294. this.page.currentPage = 1
  295. this.type = tab.name
  296. this.getPage(this.page)
  297. },
  298. handleDel: function(row, index) {
  299. var _this = this
  300. this.$confirm('是否确认删除此数据', '提示', {
  301. confirmButtonText: '确定',
  302. cancelButtonText: '取消',
  303. type: 'warning'
  304. }).then(function() {
  305. return delObj(row.id)
  306. }).then(data => {
  307. _this.$message({
  308. showClose: true,
  309. message: '删除成功',
  310. type: 'success'
  311. })
  312. this.getPage(this.page)
  313. }).catch(function(err) { })
  314. },
  315. handleSubmit(row){
  316. if(this.handleType === 'add'){
  317. addObj(Object.assign({
  318. type:this.type
  319. }, this.objData)).then(data => {
  320. this.$message({
  321. showClose: true,
  322. message: '添加成功',
  323. type: 'success'
  324. })
  325. this.getPage(this.page)
  326. this.dialog1Visible = false
  327. })
  328. }
  329. if(this.handleType === 'edit'){
  330. putObj(this.objData).then(data => {
  331. this.$message({
  332. showClose: true,
  333. message: '修改成功',
  334. type: 'success'
  335. })
  336. this.getPage(this.page)
  337. this.dialog1Visible = false
  338. })
  339. }
  340. },
  341. }
  342. }
  343. </script>