3
0

WeChatAppManage.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="org-manage">
  3. <div class="part-box part-box-filter part-box-flex">
  4. <el-form ref="FilterForm" label-position="left" inline>
  5. <el-form-item label="应用ID">
  6. <el-input
  7. v-model="filter.id"
  8. placeholder="应用ID"
  9. clearable
  10. ></el-input>
  11. </el-form-item>
  12. <el-form-item label="模糊查询">
  13. <el-input
  14. v-model="filter.nameStartWith"
  15. placeholder="名称前缀"
  16. clearable
  17. ></el-input>
  18. </el-form-item>
  19. <el-form-item label-width="0px">
  20. <el-button type="primary" icon="ios-search" @click="toPage(1)"
  21. >查询</el-button
  22. >
  23. <el-button
  24. v-if="checkPrivilege('WXAPP_INSERT')"
  25. type="success"
  26. icon="md-add"
  27. @click="toAdd"
  28. >新增</el-button
  29. >
  30. </el-form-item>
  31. </el-form>
  32. </div>
  33. <div class="part-box part-box-pad">
  34. <el-table ref="TableList" :data="dataList">
  35. <el-table-column prop="id" label="ID" width="260"></el-table-column>
  36. <el-table-column prop="name" label="名称"> </el-table-column>
  37. <el-table-column prop="createTime" label="创建时间" width="160">
  38. <span slot-scope="scope">{{
  39. scope.row.createTime | timestampFilter
  40. }}</span>
  41. </el-table-column>
  42. <el-table-column prop="updateTime" label="修改时间" width="160">
  43. <span slot-scope="scope">{{
  44. scope.row.updateTime | timestampFilter
  45. }}</span>
  46. </el-table-column>
  47. <el-table-column
  48. v-if="checkPrivilege('WXAPP_EDIT')"
  49. class-name="action-column"
  50. label="操作"
  51. width="100"
  52. >
  53. <template slot-scope="scope">
  54. <el-button
  55. class="btn-primary"
  56. type="text"
  57. @click="toEdit(scope.row)"
  58. >编辑</el-button
  59. >
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <div class="part-page">
  64. <el-pagination
  65. background
  66. layout="total,prev, pager, next"
  67. :current-page="current"
  68. :total="total"
  69. :page-size="size"
  70. @current-change="toPage"
  71. >
  72. </el-pagination>
  73. </div>
  74. </div>
  75. <el-dialog
  76. v-if="checkPrivilege('WXAPP_EDIT') || checkPrivilege('WXAPP_INSERT')"
  77. :visible.sync="visible"
  78. top="10vh"
  79. width="600px"
  80. append-to-body
  81. :close-on-click-modal="false"
  82. :close-on-press-escape="false"
  83. :title="`${modifyType === 'update' ? '修改' : '新增'}小程序`"
  84. >
  85. <el-form ref="form" :model="modalForm" :rules="rules" label-width="100px">
  86. <el-form-item prop="id" label="应用ID:">
  87. <el-input
  88. :disabled="modifyType === 'update'"
  89. v-model.trim="modalForm.id"
  90. placeholder="请输入应用ID"
  91. clearable
  92. ></el-input>
  93. </el-form-item>
  94. <el-form-item prop="name" label="名称:">
  95. <el-input
  96. v-model.trim="modalForm.name"
  97. placeholder="请输入应用名称"
  98. clearable
  99. ></el-input>
  100. </el-form-item>
  101. <el-form-item prop="secret" label="应用密钥:">
  102. <el-input
  103. v-model.trim="modalForm.secret"
  104. placeholder="请输入应用密钥"
  105. clearable
  106. ></el-input>
  107. </el-form-item>
  108. </el-form>
  109. <div slot="footer">
  110. <el-button type="danger" @click="cancel" plain>取消</el-button>
  111. <el-button type="primary" :disabled="isSubmit" @click="submit"
  112. >确认</el-button
  113. >
  114. </div>
  115. </el-dialog>
  116. </div>
  117. </template>
  118. <script>
  119. // eslint-disable-next-line no-unused-vars
  120. import { getWeChatAppList, insertWeChatApp, updateWeChatApp } from "../api";
  121. export default {
  122. name: "we-chat-app-manage",
  123. data() {
  124. return {
  125. current: 1,
  126. size: this.GLOBAL.pageSize,
  127. total: 0,
  128. dataList: [],
  129. filter: {
  130. id: "",
  131. nameStartWith: "",
  132. },
  133. modalForm: {
  134. id: "",
  135. name: "",
  136. secret: "",
  137. },
  138. modifyType: "insert",
  139. visible: false,
  140. isSubmit: false,
  141. rules: {
  142. id: [{ required: true, message: "请填写小程序AppId" }],
  143. name: [{ required: true, message: "请填写小程序名称" }],
  144. secret: [{ required: true, message: "请填写小程序名称" }],
  145. },
  146. };
  147. },
  148. watch: {
  149. visible(v) {
  150. this.$refs.form?.clearValidate();
  151. },
  152. },
  153. created() {
  154. this.toPage(1);
  155. },
  156. methods: {
  157. async getList() {
  158. try {
  159. const data = {
  160. ...this.filter,
  161. pageNumber: this.current,
  162. pageSize: this.size,
  163. };
  164. const result = await getWeChatAppList(data);
  165. this.dataList = result.records;
  166. this.total = result.total;
  167. } catch (error) {
  168. console.error(error);
  169. error.message && this.$message.error(error.message);
  170. }
  171. },
  172. toAdd() {
  173. this.modifyType = "insert";
  174. this.modalForm = this.$options.data.call(this).modalForm;
  175. this.$nextTick(() => {
  176. this.visible = true;
  177. });
  178. },
  179. toEdit(row) {
  180. this.modifyType = "update";
  181. const { id, name, secret } = row;
  182. this.modalForm = { id, name, secret };
  183. this.visible = true;
  184. },
  185. cancel() {
  186. this.visible = false;
  187. },
  188. toPage(page) {
  189. this.current = page;
  190. this.getList();
  191. },
  192. async submit() {
  193. if (this.isSubmit) {
  194. return;
  195. }
  196. this.isSubmit = true;
  197. const isUpdate = this.modifyType === "update";
  198. const api = isUpdate ? updateWeChatApp : insertWeChatApp;
  199. try {
  200. await this.$refs.form.validate();
  201. await api(this.modalForm);
  202. this.getList();
  203. this.$message.success(`${isUpdate ? "修改" : "新增"}成功`);
  204. this.visible = false;
  205. } catch (error) {
  206. error.message && this.$message.error(error.message);
  207. }
  208. this.isSubmit = false;
  209. },
  210. },
  211. };
  212. </script>