index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
  4. <el-form-item label="" prop="corpName">
  5. <el-input v-model="queryParams.corpName" placeholder="企微名称" clearable size="small" style="width: 140px"
  6. @keyup.enter.native="getList" />
  7. </el-form-item>
  8. <el-form-item label="" prop="originCorpId">
  9. <el-input v-model="queryParams.originCorpId" placeholder="企微ID" clearable size="small" style="width: 140px"
  10. @keyup.enter.native="getList" />
  11. </el-form-item>
  12. <el-form-item label="" prop="authStatus">
  13. <el-select v-model="queryParams.authStatus" placeholder="授权状态" clearable filterable style="width: 140px"
  14. size="small" @keyup.enter.native="handleQuery">
  15. <el-option label="成功授权" :value="1" />
  16. <el-option label="取消授权" :value="-1" />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item label="" prop="configStatus">
  20. <el-select v-model="queryParams.configStatus" placeholder="配置状态" clearable filterable style="width: 140px"
  21. size="small" @keyup.enter.native="handleQuery">
  22. <el-option label="未配置" value="ING" />
  23. <el-option label="配置成功" value="SUCCESS" />
  24. <el-option label="配置失败" value="ERROR" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button type="cyan" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
  29. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  30. </el-form-item>
  31. </el-form>
  32. <el-row :gutter="10" class="mb8" align="middle">
  33. <el-col :span="1.5">
  34. <div class="grid-content">
  35. <el-button type="primary" size="mini" @click="warrantHandle">企微授权</el-button>
  36. </div>
  37. </el-col>
  38. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  39. </el-row>
  40. <el-table :data="corpList" v-loading="loading" size="mini">
  41. <el-table-column label="企微名称" prop="corpName" width="150" align="center" fixed="left" />
  42. <el-table-column label="企微头像" prop="corpSquareLogoUrl" align="center" width="150">
  43. <template slot-scope="scope">
  44. <el-image style="height: 23px" :src="scope.row.corpSquareLogoUrl" fit="fit" />
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="企微ID" prop="originCorpId" align="center" width="150" />
  48. <el-table-column label="用户规模" prop="corpUserMax" align="center" width="100" />
  49. <el-table-column label="授权方企业类型" prop="corpType" align="center" width="150">
  50. <template slot-scope="scope">{{ scope.row.corpType | filterCorpType }}</template>
  51. </el-table-column>
  52. <el-table-column label="认证到期时间" prop="verifiedEndTime" align="center" width="120" />
  53. <el-table-column label="授权状态" prop="authStatus" align="center" width="120">
  54. <template slot-scope="scope">
  55. <el-tag type="success" v-if="scope.row.authStatus === 1">成功授权</el-tag>
  56. <el-tag type="danger" v-else>取消授权</el-tag>
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="配置状态" prop="configStatus" align="center" width="120">
  60. <template slot-scope="scope">
  61. <el-tag type="success" v-if="scope.row.configStatus === 'SUCCESS'">配置成功</el-tag>
  62. <el-tag type="warning" v-else-if="scope.row.configStatus === 'ING'">未配置</el-tag>
  63. <el-tag type="danger" v-else>配置失败</el-tag>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="回调地址" prop="externalUserCallbackUrl" width="200" :show-overflow-tooltip="true">
  67. <template slot-scope="scope">
  68. <a style="color: #1890ff;" @click="copy(scope.row.externalUserCallbackUrl)">{{
  69. scope.row.externalUserCallbackUrl }}</a>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="Token" prop="externalUserToken" width="150" :show-overflow-tooltip="true">
  73. <template slot-scope="scope">
  74. <a style="color: #1890ff;" @click="copy(scope.row.externalUserToken)">{{ scope.row.externalUserToken
  75. }}</a>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="AESKey" prop="externalUserAesKey" width="150" :show-overflow-tooltip="true">
  79. <template slot-scope="scope">
  80. <a style="color: #1890ff;" @click="copy(scope.row.externalUserAesKey)">{{ scope.row.externalUserAesKey
  81. }}</a>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="备注" prop="remark" width="250" :show-overflow-tooltip="true" />
  85. <el-table-column label="操作" width="200" align="center" class-name="small-padding fixed-width" fixed="right">
  86. <template slot-scope="scope">
  87. <template v-if="scope.row.authStatus === 1">
  88. <el-button size="mini" type="text" icon="el-icon-refresh"
  89. @click="handleRefresh(scope.row)">刷新</el-button>
  90. <el-button size="mini" type="text" icon="el-icon-refresh"
  91. @click="setSecretHandle(scope.row)">配置密钥</el-button>
  92. <template v-if="scope.row.configStatus === 'SUCCESS'">
  93. <el-dropdown style="margin-left: 7px;">
  94. <el-button class="el-dropdown-link" size="mini" type="text">更多<i
  95. class="el-icon-arrow-down el-icon--right"></i></el-button>
  96. <el-dropdown-menu slot="dropdown">
  97. <el-dropdown-item><el-button size="mini" type="text" icon="el-icon-refresh"
  98. @click="handleSync(scope.row)">同步所有</el-button></el-dropdown-item>
  99. <el-dropdown-item><el-button size="mini" type="text" icon="el-icon-tickets"
  100. @click="handleMailList(scope.row)">企微通讯录</el-button></el-dropdown-item>
  101. </el-dropdown-menu>
  102. </el-dropdown>
  103. </template>
  104. </template>
  105. </template>
  106. </el-table-column>
  107. </el-table>
  108. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  109. @pagination="getList" />
  110. <setSecret :value="secretData" :visible="setShow" @close="setShow = false; secretData = {}"
  111. @change="closeSetSecret(); getList()" />
  112. <mailList :corpId="corpId" :visible="mailShow" @close="mailShow = false; corpId = null" />
  113. </div>
  114. </template>
  115. <script>
  116. import { getCorpToAuth, getCorpList, putRefreshCorp, putSyncAllCorpUser } from "@/api/accounts/corpWeChat";
  117. import setSecret from './setSecret.vue'
  118. import mailList from './mailList.vue'
  119. export default {
  120. name: 'corp',
  121. components: { setSecret, mailList },
  122. data() {
  123. return {
  124. showSearch: true,
  125. loading: false,
  126. queryParams: {
  127. pageSize: 20,
  128. pageNum: 1,
  129. corpName: '',
  130. originCorpId: '',
  131. authStatus: 1
  132. },
  133. corpList: [],
  134. total: 0,
  135. setShow: false,
  136. secretData: {},
  137. mailShow: false,
  138. corpId: null,
  139. }
  140. },
  141. mounted() {
  142. this.$nextTick(() => {
  143. window.addEventListener('storage', this.listener)
  144. })
  145. },
  146. beforeDestroy() { // 在组件生命周期结束的时候销毁。
  147. window.removeEventListener('storage', this.listener, false)
  148. },
  149. created() {
  150. this.getList()
  151. },
  152. filters: {
  153. filterCorpType(val) {
  154. if (val) {
  155. return { verified: '认证号', unverified: '注册号' }[val]
  156. }
  157. return '-1'
  158. }
  159. },
  160. methods: {
  161. copy(str) {
  162. let element = document.createElement("textarea");
  163. element.id = 'myTextarea'
  164. element.textContent = str
  165. document.body.append(element);
  166. (document.getElementById('myTextarea')).select();
  167. document.execCommand("Copy")
  168. document.body.removeChild(element);
  169. this.msgSuccess(`复制成功:${str}`);
  170. },
  171. handleSync(row) {
  172. const loading = this.$loading({
  173. lock: true,
  174. text: 'Loading',
  175. spinner: 'el-icon-loading',
  176. background: 'rgba(0, 0, 0, 0.7)'
  177. });
  178. putSyncAllCorpUser(row.corpId).then(res => {
  179. loading.close()
  180. this.getList()
  181. }).catch(() => loading.close())
  182. },
  183. handleMailList(row) {
  184. this.mailShow = true
  185. this.corpId = row.corpId
  186. },
  187. listener(e) {
  188. if (e.key === 'corpAdMp') {
  189. if (e.newValue === 'ok') {
  190. this.getList()
  191. this.msgSuccess("授权成功");
  192. localStorage.removeItem('corpAdMp')
  193. } else {
  194. this.$message.error('授权失败');
  195. localStorage.removeItem('corpAdMp')
  196. }
  197. }
  198. },
  199. getList() {
  200. this.loading = true
  201. getCorpList(this.queryParams).then(res => {
  202. this.corpList = res.data.records
  203. this.total = res.data.total
  204. this.loading = false
  205. }).catch(() => this.loading = false)
  206. },
  207. /** 重置搜索条件 */
  208. resetQuery() {
  209. this.resetForm("queryForm");
  210. this.getList();
  211. },
  212. /** 企微授权 */
  213. warrantHandle() {
  214. getCorpToAuth({ redirectUri: encodeURIComponent(process.env.VUE_APP_CORP_URL) }).then(res => {
  215. if (res.data) {
  216. window.open(res.data)
  217. }
  218. })
  219. },
  220. /** 刷新企微信息 */
  221. handleRefresh(row) {
  222. const loading = this.$loading({
  223. lock: true,
  224. text: 'Loading',
  225. spinner: 'el-icon-loading',
  226. background: 'rgba(0, 0, 0, 0.7)'
  227. });
  228. putRefreshCorp(row.corpId).then(res => {
  229. loading.close()
  230. this.getList()
  231. }).catch(() => loading.close())
  232. },
  233. /** 配置密钥 */
  234. setSecretHandle(row) {
  235. this.setShow = true
  236. this.secretData = {
  237. corpId: row.corpId,
  238. originCorpId: row.originCorpId,
  239. externalUserSecret: row.externalUserSecret,
  240. bookAgentId: row.bookAgentId,
  241. remark: row.remark
  242. }
  243. },
  244. /** 关闭配置 */
  245. closeSetSecret() {
  246. this.setShow = false
  247. this.secretData = {}
  248. }
  249. }
  250. }
  251. </script>