feishuConfig.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">
  4. <el-form-item label="飞书账号" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入飞书账号"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="appId" prop="appId">
  14. <el-input
  15. v-model="queryParams.appId"
  16. placeholder="请输入appId"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="状态" prop="status">
  23. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  24. <el-option
  25. v-for="item in statusOptions"
  26. :key="item.value"
  27. :label="item.label"
  28. :value="item.value"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  34. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  35. </el-form-item>
  36. </el-form>
  37. <el-row :gutter="10" class="mb8">
  38. <el-col :span="1.5">
  39. <el-button
  40. type="primary"
  41. plain
  42. icon="el-icon-plus"
  43. size="mini"
  44. @click="handleAdd"
  45. v-hasPermi="['course:feishuConfig:add']"
  46. >新增</el-button>
  47. </el-col>
  48. <el-col :span="1.5">
  49. <el-button
  50. type="success"
  51. plain
  52. icon="el-icon-edit"
  53. size="mini"
  54. :disabled="single"
  55. @click="handleUpdate"
  56. v-hasPermi="['course:feishuConfig:edit']"
  57. >修改</el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="danger"
  62. plain
  63. icon="el-icon-delete"
  64. size="mini"
  65. :disabled="multiple"
  66. @click="handleDelete"
  67. v-hasPermi="['course:feishuConfig:remove']"
  68. >删除</el-button>
  69. </el-col>
  70. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  71. </el-row>
  72. <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange" border>
  73. <el-table-column type="selection" width="55" align="center" />
  74. <el-table-column label="ID" align="center" prop="id" width="80" />
  75. <el-table-column label="飞书账号" align="center" prop="name" />
  76. <el-table-column label="appId" align="center" prop="appId" min-width="160" show-overflow-tooltip />
  77. <el-table-column label="appSecret" align="center" prop="appSecret" min-width="180" show-overflow-tooltip />
  78. <el-table-column label="状态" align="center" prop="status" width="100">
  79. <template slot-scope="scope">
  80. <el-tag :type="statusTagType(scope.row.status)">
  81. {{ getStatusLabel(scope.row.status) }}
  82. </el-tag>
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip />
  86. <el-table-column label="创建时间" align="center" prop="createTime" width="170" />
  87. <el-table-column label="修改时间" align="center" prop="updateTime" width="170" />
  88. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
  89. <template slot-scope="scope">
  90. <el-button
  91. size="mini"
  92. type="text"
  93. icon="el-icon-edit"
  94. @click="handleUpdate(scope.row)"
  95. v-hasPermi="['course:feishuConfig:edit']"
  96. >修改</el-button>
  97. <el-button
  98. size="mini"
  99. type="text"
  100. icon="el-icon-delete"
  101. @click="handleDelete(scope.row)"
  102. v-hasPermi="['course:feishuConfig:remove']"
  103. >删除</el-button>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <pagination
  108. v-show="total > 0"
  109. :total="total"
  110. :page.sync="queryParams.pageNum"
  111. :limit.sync="queryParams.pageSize"
  112. @pagination="getList"
  113. />
  114. <el-dialog :title="title" :visible.sync="open" width="680px" append-to-body>
  115. <el-form ref="form" :model="form" :rules="rules" label-width="110px">
  116. <el-form-item label="飞书账号" prop="name">
  117. <el-input v-model="form.name" placeholder="请输入飞书账号名称" />
  118. </el-form-item>
  119. <el-form-item label="appId" prop="appId">
  120. <el-input v-model="form.appId" placeholder="请输入飞书应用 AppId" />
  121. </el-form-item>
  122. <el-form-item label="appSecret" prop="appSecret">
  123. <el-input v-model="form.appSecret" placeholder="请输入飞书应用 AppSecret" show-password />
  124. </el-form-item>
  125. <el-form-item label="状态" prop="status">
  126. <el-select v-model="form.status" placeholder="请选择状态" style="width: 100%">
  127. <el-option
  128. v-for="item in statusOptions"
  129. :key="item.value"
  130. :label="item.label"
  131. :value="item.value"
  132. />
  133. </el-select>
  134. </el-form-item>
  135. <el-form-item label="权限导入示例">
  136. <el-input
  137. :value="permissionImportExample"
  138. type="textarea"
  139. :rows="12"
  140. readonly
  141. class="permission-example"
  142. />
  143. <el-button type="primary" plain size="mini" icon="el-icon-document-copy" style="margin-top: 8px" @click="copyPermissionExample">
  144. 一键复制
  145. </el-button>
  146. </el-form-item>
  147. <el-form-item label="备注" prop="remark">
  148. <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="备注" />
  149. </el-form-item>
  150. </el-form>
  151. <div slot="footer" class="dialog-footer">
  152. <el-button type="primary" @click="submitForm">确 定</el-button>
  153. <el-button @click="cancel">取 消</el-button>
  154. </div>
  155. </el-dialog>
  156. </div>
  157. </template>
  158. <script>
  159. import {
  160. listFeishuConfig,
  161. getFeishuConfig,
  162. addFeishuConfig,
  163. updateFeishuConfig,
  164. delFeishuConfig
  165. } from '@/api/course/feishuConfig'
  166. export default {
  167. name: 'FeishuConfig',
  168. data() {
  169. return {
  170. loading: false,
  171. showSearch: true,
  172. ids: [],
  173. single: true,
  174. multiple: true,
  175. total: 0,
  176. list: [],
  177. title: '',
  178. open: false,
  179. statusOptions: [
  180. { label: '正常', value: 1 },
  181. { label: '停用', value: 0 },
  182. { label: '已封禁', value: -1 }
  183. ],
  184. permissionImportExample: `{
  185. "scopes": {
  186. "tenant": [
  187. "docs:permission.setting:read",
  188. "docs:permission.setting:write_only",
  189. "docx:document",
  190. "drive:drive",
  191. "space:document:delete"
  192. ],
  193. "user": []
  194. }
  195. }`,
  196. queryParams: {
  197. pageNum: 1,
  198. pageSize: 10,
  199. name: null,
  200. appId: null,
  201. status: null
  202. },
  203. form: {},
  204. rules: {
  205. name: [{ required: true, message: '飞书账号不能为空', trigger: 'blur' }],
  206. appId: [{ required: true, message: 'appId不能为空', trigger: 'blur' }],
  207. appSecret: [{ required: true, message: 'appSecret不能为空', trigger: 'blur' }],
  208. status: [{ required: true, message: '状态不能为空', trigger: 'change' }]
  209. }
  210. }
  211. },
  212. created() {
  213. this.getList()
  214. },
  215. methods: {
  216. getList() {
  217. this.loading = true
  218. listFeishuConfig(this.queryParams).then(response => {
  219. this.list = response.rows
  220. this.total = response.total
  221. this.loading = false
  222. }).catch(() => {
  223. this.loading = false
  224. })
  225. },
  226. handleQuery() {
  227. this.queryParams.pageNum = 1
  228. this.getList()
  229. },
  230. resetQuery() {
  231. this.resetForm('queryForm')
  232. this.handleQuery()
  233. },
  234. handleSelectionChange(selection) {
  235. this.ids = selection.map(item => item.id)
  236. this.single = selection.length !== 1
  237. this.multiple = !selection.length
  238. },
  239. reset() {
  240. this.form = {
  241. id: null,
  242. name: null,
  243. appId: null,
  244. appSecret: null,
  245. status: 1,
  246. remark: null
  247. }
  248. this.resetForm('form')
  249. },
  250. handleAdd() {
  251. this.reset()
  252. this.open = true
  253. this.title = '新增飞书配置'
  254. },
  255. handleUpdate(row) {
  256. this.reset()
  257. const id = row.id || this.ids[0]
  258. getFeishuConfig(id).then(response => {
  259. this.form = response.data
  260. this.open = true
  261. this.title = '修改飞书配置'
  262. })
  263. },
  264. submitForm() {
  265. this.$refs['form'].validate(valid => {
  266. if (!valid) {
  267. return
  268. }
  269. const req = this.form.id != null ? updateFeishuConfig(this.form) : addFeishuConfig(this.form)
  270. req.then(response => {
  271. if (response.code !== 200) {
  272. this.msgError(response.msg)
  273. return
  274. }
  275. this.msgSuccess(this.form.id != null ? '修改成功' : '新增成功')
  276. this.open = false
  277. this.getList()
  278. })
  279. })
  280. },
  281. cancel() {
  282. this.open = false
  283. this.reset()
  284. },
  285. handleDelete(row) {
  286. const ids = row.id || this.ids
  287. this.$confirm('是否确认删除飞书配置编号为"' + ids + '"的数据项?', '警告', {
  288. confirmButtonText: '确定',
  289. cancelButtonText: '取消',
  290. type: 'warning'
  291. }).then(() => {
  292. return delFeishuConfig(ids)
  293. }).then(() => {
  294. this.getList()
  295. this.msgSuccess('删除成功')
  296. }).catch(() => {})
  297. },
  298. getStatusLabel(status) {
  299. const map = { 1: '正常', 0: '停用', [-1]: '已封禁' }
  300. return map[status] || '未知'
  301. },
  302. statusTagType(status) {
  303. if (status === 1) return 'success'
  304. if (status === 0) return 'warning'
  305. if (status === -1) return 'danger'
  306. return 'info'
  307. },
  308. copyPermissionExample() {
  309. navigator.clipboard.writeText(this.permissionImportExample).then(() => {
  310. this.msgSuccess('已复制到剪贴板')
  311. }).catch(() => {
  312. this.msgError('复制失败,请手动复制')
  313. })
  314. }
  315. }
  316. }
  317. </script>
  318. <style scoped>
  319. .permission-example >>> textarea {
  320. font-family: Consolas, Monaco, monospace;
  321. background-color: #f5f7fa;
  322. color: #606266;
  323. cursor: default;
  324. }
  325. </style>