OpenMgmt2.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <template>
  2. <div class="open-mgmt">
  3. <Loading :top="200" bgColor="rgba(103, 103, 103, 0.27)" type="1" v-show="isLoading"></Loading>
  4. <!-- 列表 -->
  5. <div class="open-mgmt-left">
  6. <div class="open-header">
  7. <span>{{ $t("settings.openList") }}</span>
  8. <div class="open-action">
  9. <!-- <Icon type="md-add" size="18" style="margin-right: 10px" color="rgb(115 115 115)" @click="editOpen(true, true)" /> -->
  10. <Icon type="md-add" size="18" style="margin-right: 10px" color="#0094FF" @click="editOpen(true, true)" />
  11. <Icon type="md-trash" size="18" color="#0094FF" @click="delOpen" />
  12. </div>
  13. </div>
  14. <vuescroll>
  15. <div class="open-left-list">
  16. <div :class="['open-list', index == nowIndex ? 'list-select': '']"
  17. v-for="(item, index) in openList"
  18. :key="index"
  19. @click="list(index)"
  20. >
  21. <span>{{ item.name }}</span>
  22. </div>
  23. </div>
  24. </vuescroll>
  25. </div>
  26. <!-- 信息 -->
  27. <div class="open-mgmt-right">
  28. <div class="open-header">
  29. <span>{{ $t("settings.openInfo") }}</span>
  30. <div class="open-action" @click="editOpen(true, false)" v-show="!isEdit">
  31. <div>
  32. <Icon type="ios-create" size="18" color="#0094FF" />
  33. <span>{{ $t("settings.edit") }}</span>
  34. </div>
  35. </div>
  36. <div class="open-action" v-show="isEdit">
  37. <div @click="keepMgmt(true)">
  38. <Icon type="md-checkmark-circle" size="18" color="#0094FF" />
  39. <span>{{ $t("settings.openKeep") }}</span>
  40. </div>
  41. <div @click="keepMgmt(false)">
  42. <Icon type="md-close-circle" size="18" color="#DDDDDD" />
  43. <span>{{ $t("settings.unedit") }}</span>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="open-right-info">
  48. <div class="open-info">
  49. <vuescroll>
  50. <div class=" dark-iview-form disabled-iview-input">
  51. <!-- <div class="open-mgmt-info"> -->
  52. <Form :model="openMgInfo" label-position="top">
  53. <div class="open-mgmt-info">
  54. <FormItem :label="$t('settings.openName')">
  55. <Input v-model="openMgInfo.name"
  56. :class="isEdit ? '' : 'open-info-disabled'"
  57. :readonly="isEdit ? false : true"></Input>
  58. </FormItem>
  59. <FormItem :label="$t('settings.token')" class="api-token" v-show="!isEdit">
  60. <div class="api-icon">
  61. <!-- 隐藏 -->
  62. <Icon :type="isTokenShow ? 'md-eye' : 'md-eye-off'" size="18" style="margin-right: 10px" color="rgb(115 115 115)" @click="isTokenShow = !isTokenShow" />
  63. <!-- 刷新 -->
  64. <Icon type="md-refresh" size="18" style="margin-right: 10px" color="rgb(115 115 115)" @click="refresh" />
  65. <!-- 复制 -->
  66. <Icon type="ios-copy" size="18" color="rgb(115 115 115)" @click="copyToken" />
  67. </div>
  68. <Input
  69. v-model="openMgInfo.token"
  70. type="textarea"
  71. :autosize="{ minRows: 10 }"
  72. class="open-info-disabled"
  73. readonly
  74. v-show="isTokenShow"
  75. ></Input>
  76. </FormItem>
  77. <FormItem :label="$t('settings.des')">
  78. <Input v-model="openMgInfo.descr"
  79. type="textarea"
  80. :autosize="{ minRows: 2 }"
  81. :class="isEdit ? '' : 'open-info-disabled'"
  82. :readonly="isEdit ? false : true"></Input>
  83. </FormItem>
  84. <FormItem :label="$t('settings.openStatus')">
  85. <RadioGroup v-model="openMgInfo.status">
  86. <Radio :label="1" :disabled="isEdit ? false : true">{{ $t("settings.enable") }}</Radio>
  87. <Radio :label="0" :disabled="isEdit ? false : true">{{ $t("settings.disable") }}</Radio>
  88. </RadioGroup>
  89. </FormItem>
  90. </div>
  91. <p>{{ $t('settings.webhook') }}</p>
  92. <div class="open-mgmt-info">
  93. <FormItem :label="$t('settings.domainName')">
  94. <Input v-model="openMgInfo.domain"
  95. :class="isEdit ? '' : 'open-info-disabled'"
  96. :readonly="isEdit ? false : true"></Input>
  97. </FormItem>
  98. <FormItem :label="$t('settings.subNews')">
  99. <CheckboxGroup v-model="openMgInfo.news">
  100. <Checkbox label="hhhh" :disabled="isEdit ? false : true">
  101. <span>订阅通知1</span>
  102. </Checkbox>
  103. <Checkbox label="www" :disabled="isEdit ? false : true">
  104. <span>订阅通知2</span>
  105. </Checkbox>
  106. <Checkbox label="mmm" :disabled="isEdit ? false : true">
  107. <span>订阅通知3</span>
  108. </Checkbox>
  109. <Checkbox label="wwwww" :disabled="isEdit ? false : true">
  110. <span>订阅通知4</span>
  111. </Checkbox>
  112. </CheckboxGroup>
  113. </FormItem>
  114. </div>
  115. </Form>
  116. </div>
  117. <!-- </div> -->
  118. </vuescroll>
  119. </div>
  120. <div class="open-api dark-iview-table dark-iview-page dark-iview-tabs-card">
  121. <!-- <div class="open-api"> -->
  122. <!-- <vuescroll> -->
  123. <!-- <div class="open-api-table">
  124. <p>数据写入接口</p>
  125. <Table ref="selection"
  126. :loading="isLoadList"
  127. :columns="apiListCol"
  128. :data="isEdit ? apiListSelect : apiListNow"
  129. @on-selection-change="selectionChange"
  130. ></Table>
  131. <Page :total="pageTotal" :page-size-opts="pageSizeOpts" size="small" show-sizer show-total />
  132. </div> -->
  133. <!-- </vuescroll> -->
  134. <!-- <vuescroll> -->
  135. <!-- <div class="open-api-table">
  136. <p>数据读取接口</p>
  137. <Table ref="selection"
  138. :loading="isLoadList"
  139. :columns="apiListCol"
  140. :data="isEdit ? apiListSelect : apiListNow"
  141. @on-selection-change="selectionChange"
  142. ></Table>
  143. <Page :total="pageTotal" :page-size-opts="pageSizeOpts" size="small" show-sizer show-total />
  144. </div> -->
  145. <!-- </vuescroll> -->
  146. <Tabs value="1">
  147. <TabPane :label="$t('settings.apiType1')" name="1">
  148. <div class="open-api-table">
  149. <Table ref="selection"
  150. :loading="isLoadList"
  151. :columns="apiListCol"
  152. :data="isEdit ? apiListSelect : apiListNow"
  153. @on-selection-change="selectionChange"
  154. >
  155. <template slot-scope="{ row }" slot="name">
  156. <span>{{ row.name }}</span>
  157. <Poptip trigger="hover" :content="row.descr" placement="right">
  158. <!-- <Icon type="ios-alert" /> -->
  159. <Icon type="ios-alert-outline" />
  160. </Poptip>
  161. </template>
  162. </Table>
  163. </div>
  164. </TabPane>
  165. <TabPane :label="$t('settings.apiType2')" name="2">
  166. <div class="open-api-table">
  167. <Table ref="selection"
  168. :loading="isLoadList"
  169. :columns="apiListCol"
  170. :data="isEdit ? apiListSelect : apiListNow"
  171. @on-selection-change="selectionChange"
  172. >
  173. <template slot-scope="{ row }" slot="name">
  174. <span>{{ row.name }}</span>
  175. <Poptip trigger="hover" :content="row.descr" placement="right">
  176. <!-- <Icon type="ios-alert" /> -->
  177. <Icon type="ios-alert-outline" />
  178. </Poptip>
  179. </template>
  180. </Table>
  181. </div>
  182. </TabPane>
  183. </Tabs>
  184. </div>
  185. </div>
  186. </div>
  187. </div>
  188. </template>
  189. <script>
  190. export default {
  191. name: "OpenMgmt",
  192. data() {
  193. return {
  194. isLoading: false,
  195. isLoadList: false,
  196. isTokenShow: false,
  197. schoolCode: this.$store.state.userInfo.schoolCode,
  198. openList: [], //开放平台列表
  199. openMgInfo: {}, //平台信息
  200. apiType: 1,
  201. apiListCol: [ //api表头
  202. /* {
  203. type: 'selection',
  204. width: 80,
  205. align: 'center',
  206. }, */
  207. {
  208. title: this.$t("settings.apiName"),
  209. key: "name",
  210. slot: "name"
  211. },
  212. {
  213. title: this.$t("settings.apiAddress"),
  214. key: "url",
  215. },
  216. {
  217. title: this.$t("settings.apiMethod"),
  218. key: "method",
  219. },
  220. {
  221. title: this.$t("settings.des"),
  222. key: "descr",
  223. },
  224. ],
  225. apiList: [], //api原有列表
  226. apiListSelect: [], //api选择列表
  227. apiListNow: [], //当前应用已有的api 列表
  228. pageTotal: 0,
  229. pageSizeOpts:[5, 10, 20, 30, 40],
  230. nowIndex: 0, //当前下标
  231. isEdit: false, //编辑状态
  232. isAdd: false, // 编辑/新增
  233. }
  234. },
  235. mounted () {
  236. this.getOpenList()
  237. this.getApiList()
  238. },
  239. methods: {
  240. // 获取应用列表
  241. getOpenList() {
  242. this.isLoading = true
  243. let list = []
  244. let req = {code: this.schoolCode}
  245. this.$api.openMgmt.getOpenList(req).then(
  246. res => {
  247. if (res) {
  248. list = [...res.apps]
  249. // 没有创建时间,暂时倒序
  250. list.reverse()
  251. this.openList = list
  252. this.openMgInfo = this._.cloneDeep(this.openList[this.nowIndex])
  253. this.isLoading = false
  254. }
  255. }, err => {
  256. this.$Message.warning(this.$t('settings.openModal1'))
  257. setTimeout(() => {
  258. this.isLoading = false
  259. }, 1000)
  260. })
  261. },
  262. // 获取api 列表
  263. getApiList() {
  264. this.apiList = []
  265. let reqs = {}
  266. this.$api.openMgmt.getApiList(reqs).then(res => {
  267. if (res) {
  268. let list = [...res.apis]
  269. if(list.length > 0) {
  270. // 根据auth 的大小进行排序
  271. list.sort((a, b) => {
  272. return a.auth - b.auth
  273. })
  274. }
  275. this.apiList = list
  276. this.selectApi()
  277. }
  278. }, err => {
  279. this.$Message.warning(this.$t('settings.openModal2'))
  280. setTimeout(() => {
  281. this.isLoadList = false
  282. }, 1000)
  283. })
  284. },
  285. // 筛选出该应用已有的api
  286. selectApi() {
  287. this.apiListNow = []
  288. let listSel = this._.cloneDeep(this.apiList)
  289. if(listSel.length > 0) {
  290. if(this.openMgInfo.auths.length > 0) {
  291. listSel.map(item => {
  292. this.openMgInfo.auths.map(items => {
  293. if(item.auth == items) {
  294. this.apiListNow.push({...item})
  295. item._checked = true
  296. }
  297. })
  298. })
  299. }
  300. }
  301. this.apiListSelect = listSel
  302. },
  303. // 编辑、新增
  304. editOpen (isEdit, isAdd) {
  305. this.isTokenShow = false
  306. if(this.isEdit) {
  307. return
  308. } else {
  309. this.apiListCol.unshift({
  310. type: 'selection',
  311. width: 80,
  312. align: 'center',
  313. })
  314. this.isEdit = isEdit
  315. this.isAdd = isAdd
  316. // 新增
  317. if(isAdd) {
  318. var defaultInfo = {
  319. auths: [],
  320. code: this.schoolCode,
  321. descr: null,
  322. name: this.$t('settings.opName'),
  323. school: this.schoolCode,
  324. status: 0,
  325. }
  326. this.openList.unshift(defaultInfo)
  327. this.openMgInfo = defaultInfo
  328. this.nowIndex = 0
  329. this.apiListSelect = this._.cloneDeep(this.apiList)
  330. }
  331. }
  332. },
  333. // 删除应用
  334. delOpen () {
  335. if(this.isEdit) {
  336. return
  337. } else {
  338. var titWord = this.$t("settings.delModal1") + this.openMgInfo.name + this.$t("settings.delModal2")
  339. this.$Modal.confirm({
  340. title: `${titWord}`,
  341. onOk: () => {
  342. let req = {
  343. id: this.openMgInfo.id,
  344. code: this.schoolCode
  345. }
  346. this.$api.openMgmt.delOpen(req).then(
  347. res => {
  348. this.openList.splice(this.nowIndex, 1)
  349. if(this.openList.length == this.nowIndex) {
  350. this.nowIndex = 0
  351. }
  352. this.openMgInfo = this._.cloneDeep(this.openList[this.nowIndex])
  353. this.selectApi()
  354. this.isTokenShow = false
  355. this.$Message.success(this.$t('settings.delModal3'))
  356. }, err => {
  357. this.$Message.error(this.$t('settings.delModal4'))
  358. setTimeout(() => {
  359. this.isLoading = false
  360. }, 1000)
  361. }
  362. )
  363. },
  364. onCancel: () => {
  365. this.$Message.info(this.$t('settings.delModal5'));
  366. },
  367. })
  368. }
  369. },
  370. list (index) {
  371. if(index != this.nowIndex) {
  372. this.isTokenShow = false
  373. if(this.isEdit) {
  374. if(this.isAdd) {
  375. this.openList.splice(0, 1)
  376. index = index - 1
  377. }
  378. this.isEdit = !this.isEdit
  379. this.apiListCol.splice(0, 1)
  380. }
  381. this.nowIndex = index
  382. var info = this._.cloneDeep(this.openList[index])
  383. this.openMgInfo = info
  384. this.selectApi()
  385. }
  386. },
  387. // 保存平台信息
  388. keepMgmt (type) {
  389. // this.isEdit = type
  390. if(type) {
  391. let auths = []
  392. if(this.apiListNow.length > 0) {
  393. this.apiListNow.map(item => {
  394. auths.push(item.auth)
  395. })
  396. }
  397. let req = {}
  398. if(this.isAdd) {
  399. req = this.openMgInfo
  400. req.auths = auths
  401. } else{
  402. req = {
  403. id: this.openMgInfo.id,
  404. auths,
  405. code: this.schoolCode,
  406. descr: this.openMgInfo.descr,
  407. name: this.openMgInfo.name,
  408. school: this.schoolCode,
  409. status: this.openMgInfo.status,
  410. }
  411. }
  412. this.$api.openMgmt.editOpenInfo(req).then(res => {
  413. if (res) {
  414. console.log(res.app);
  415. this.openMgInfo = res.app
  416. this.refreshToken()
  417. this.getOpenList()
  418. this.selectApi()
  419. this.$Message.success(this.$t('settings.keepModal1'));
  420. }
  421. }, err => {
  422. this.$Message.warning(this.$t('settings.keepModal2'))
  423. setTimeout(() => {
  424. this.isLoading = false
  425. }, 1000)
  426. })
  427. } else {
  428. this.openList = this.openList.filter(i => i.id)
  429. this.openMgInfo = this._.cloneDeep(this.openList[this.nowIndex])
  430. this.selectApi()
  431. }
  432. this.apiListCol.splice(0, 1)
  433. this.isEdit = false
  434. },
  435. // 刷新token
  436. refresh() {
  437. if(this.isTokenShow) {
  438. this.$Modal.confirm({
  439. title: this.$t('settings.refreshModal3'),
  440. onOk: () => {
  441. this.refreshToken()
  442. },
  443. onCancel: () => {
  444. this.$Message.info(this.$t('settings.refreshModal4'));
  445. },
  446. })
  447. }
  448. },
  449. refreshToken() {
  450. let req = {
  451. id: this.openMgInfo.id,
  452. code: this.openMgInfo.school
  453. }
  454. this.$api.openMgmt.getToken(req).then(res => {
  455. if (res) {
  456. this.openList[this.nowIndex].token = res.auth_token
  457. this.openMgInfo.token = res.auth_token
  458. if(!this.isAdd) {
  459. this.$Message.success(this.$t('settings.refreshModal1'));
  460. }
  461. }
  462. }, err => {
  463. this.$Message.warning(this.$t('settings.refreshModal2'))
  464. setTimeout(() => {
  465. this.isLoading = false
  466. }, 1000)
  467. })
  468. },
  469. copyToken() {
  470. if(this.isTokenShow) {
  471. var that = this;
  472. this.$copyText(this.openMgInfo.token).then(
  473. function(e) {
  474. that.$Message.success(that.$t('settings.copyModal1'));
  475. },
  476. function(e) {
  477. that.$Message.error(that.$t('settings.copyModal2'));
  478. }
  479. );
  480. }
  481. },
  482. selectionChange(selection) {
  483. this.apiListNow = selection
  484. console.log(selection);
  485. },
  486. selectMenu(name) {
  487. console.log(name);
  488. this.apiType = name
  489. },
  490. }
  491. }
  492. </script>
  493. <style lang="less">
  494. @import "./OpenMgmt2.less";
  495. </style>