| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- const fs = require('fs')
- const path = 'd:/ylrz_saas_new/adminui/src/views/saas/tenant/ChannelManage.vue'
- const content = `<template>
- <div v-loading="loading">
- <el-alert type="info" :closable="false" show-icon style="margin-bottom: 12px">
- <template slot="title">{{ labels.alertTitle }}</template>
- </el-alert>
- <el-table :data="plugins" border size="small" max-height="420">
- <el-table-column :label="labels.colGrant" width="70" align="center">
- <template slot-scope="{ row }">
- <el-checkbox v-model="row.granted" />
- </template>
- </el-table-column>
- <el-table-column prop="channelType" :label="labels.colCode" width="110" />
- <el-table-column :label="labels.colName" min-width="130">
- <template slot-scope="{ row }">
- <i :class="row.icon" style="margin-right: 4px" />{{ row.displayName }}
- </template>
- </el-table-column>
- <el-table-column label="SDK" width="88" align="center">
- <template slot-scope="{ row }">
- <el-tag :type="row.hasMessageChannel ? 'success' : 'warning'" size="mini">
- {{ row.hasMessageChannel ? labels.sdkReady : labels.sdkPending }}
- </el-tag>
- </template>
- </el-table-column>
- <el-table-column :label="labels.colEnable" width="72" align="center">
- <template slot-scope="{ row }">
- <el-switch
- v-model="row._enabled"
- :disabled="!row.granted || !row.hasMessageChannel"
- />
- </template>
- </el-table-column>
- <el-table-column :label="labels.colCredential" min-width="260">
- <template slot-scope="{ row }">
- <template v-if="!row.granted">
- <span class="text-muted">{{ labels.notGranted }}</span>
- </template>
- <template v-else-if="isBuiltin(row.channelType)">
- <el-tag size="mini" type="info">{{ labels.builtinNoConfig }}</el-tag>
- </template>
- <template v-else-if="row.channelType === 'WHATSAPP'">
- <div class="config-row">
- <el-input v-model="row._waPhone" placeholder="Phone Number ID" size="mini" class="cfg-md" />
- <el-input v-model="row._waToken" placeholder="Token" size="mini" class="cfg-md" type="password" show-password />
- </div>
- </template>
- <template v-else>
- <el-input v-model="row._apiKey" placeholder="API Key / Webhook URL" size="mini" class="cfg-lg" />
- </template>
- </template>
- </el-table-column>
- <el-table-column :label="labels.colAction" width="88" fixed="right" align="center">
- <template slot-scope="{ row }">
- <el-button
- type="text"
- size="mini"
- :disabled="!row.granted || !row._enabled"
- @click="testChannel(row)"
- >{{ labels.test }}</el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </template>
- <script>
- import { getTenantLobsterChannels, saveTenantLobsterChannels, testTenantLobsterChannel } from '@/api/admin/lobsterChannel'
- const LABELS = {
- alertTitle: '\\u6e20\\u9053\\u7531\\u603b\\u540e\\u53f0\\u7edf\\u4e00\\u5f00\\u901a\\u4e0e\\u914d\\u7f6e\\uff08\\u6d89\\u53ca\\u79df\\u6237\\u8ba1\\u8d39\\uff09\\u3002\\u52fe\\u9009\\u300c\\u5f00\\u901a\\u300d\\u6388\\u6743\\u6e20\\u9053\\uff1b\\u5bf9\\u5df2\\u5f00\\u901a\\u6e20\\u9053\\u53ef\\u542f\\u7528\\u5e76\\u586b\\u5199\\u7b2c\\u4e09\\u65b9\\u51ed\\u8bc1\\u3002',
- colGrant: '\\u5f00\\u901a',
- colCode: '\\u7f16\\u7801',
- colName: '\\u6e20\\u9053',
- colEnable: '\\u542f\\u7528',
- colCredential: '\\u51ed\\u8bc1',
- colAction: '\\u64cd\\u4f5c',
- sdkReady: '\\u5df2\\u63a5\\u5165',
- sdkPending: '\\u5f85\\u63a5\\u5165',
- notGranted: '\\u672a\\u5f00\\u901a',
- builtinNoConfig: '\\u5185\\u7f6e\\u514d\\u914d\\u7f6e',
- test: '\\u6d4b\\u8bd5',
- needOneChannel: '\\u8bf7\\u81f3\\u5c11\\u5f00\\u901a\\u4e00\\u4e2a\\u6e20\\u9053',
- saveOk: '\\u6e20\\u9053\\u914d\\u7f6e\\u5df2\\u4fdd\\u5b58',
- testOk: '\\u8fde\\u63a5\\u6b63\\u5e38',
- testFail: '\\u8fde\\u63a5\\u5931\\u8d25'
- }
- export default {
- name: 'TenantChannelManage',
- props: {
- tenantId: { type: [Number, String], required: true }
- },
- data() {
- return {
- loading: false,
- plugins: [],
- labels: LABELS
- }
- },
- watch: {
- tenantId: {
- immediate: true,
- handler(v) {
- if (v) this.load()
- }
- }
- },
- methods: {
- isBuiltin(type) {
- return type === 'QW' || type === 'WX' || type === 'IM'
- },
- load() {
- this.loading = true
- getTenantLobsterChannels(this.tenantId).then(res => {
- const list = res.data || []
- this.plugins = list.map(row => this.decorateRow(row))
- }).finally(() => { this.loading = false })
- },
- decorateRow(row) {
- const cfg = this.parseConfig(row.configJson)
- return {
- ...row,
- granted: row.granted === true || row.granted === 1,
- _enabled: row.enabled === 1 || row.enabled === true,
- _waPhone: cfg.phoneNumberId || '',
- _waToken: cfg.token || '',
- _apiKey: cfg.apiKey || ''
- }
- },
- parseConfig(json) {
- if (!json) return {}
- try {
- return typeof json === 'string' ? JSON.parse(json) : json
- } catch (e) {
- return {}
- }
- },
- buildPayload() {
- const channelTypes = this.plugins.filter(p => p.granted).map(p => p.channelType)
- if (!channelTypes.length) {
- this.$message.warning(LABELS.needOneChannel)
- return null
- }
- const plugins = this.plugins.filter(p => p.granted).map(p => {
- let config = {}
- if (!this.isBuiltin(p.channelType)) {
- if (p.channelType === 'WHATSAPP') {
- config = { phoneNumberId: p._waPhone, token: p._waToken }
- } else {
- config = { apiKey: p._apiKey }
- }
- }
- return {
- channelType: p.channelType,
- enabled: p._enabled,
- config
- }
- })
- return { channelTypes, plugins }
- },
- save() {
- const payload = this.buildPayload()
- if (!payload) return Promise.reject()
- this.loading = true
- return saveTenantLobsterChannels(this.tenantId, payload).then(() => {
- this.$message.success(LABELS.saveOk)
- this.load()
- this.$emit('success')
- }).finally(() => { this.loading = false })
- },
- testChannel(row) {
- testTenantLobsterChannel(this.tenantId, row.channelType).then(res => {
- const r = res.data || {}
- this.$message({
- type: r.ok ? 'success' : 'error',
- message: r.reason || (r.ok ? LABELS.testOk : LABELS.testFail)
- })
- })
- }
- }
- }
- </script>
- <style scoped>
- .config-row { display: flex; gap: 8px; flex-wrap: wrap; }
- .cfg-md { width: 140px; }
- .cfg-lg { width: 200px; }
- .text-muted { color: #909399; font-size: 12px; }
- </style>
- `
- fs.writeFileSync(path, content, 'utf8')
- console.log('written', path)
|