index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  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="所属公司" prop="companyId">
  14. <el-select
  15. v-model="queryParams.companyId"
  16. filterable
  17. remote
  18. reserve-keyword
  19. placeholder="请输入公司名称搜索"
  20. :remote-method="searchCompanies"
  21. :loading="companySearchLoading"
  22. style="width: 220px"
  23. clearable
  24. size="small"
  25. >
  26. <el-option
  27. v-for="item in companyOptions"
  28. :key="item.dictValue"
  29. :label="item.dictLabel"
  30. :value="item.dictValue"
  31. />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="appid" prop="appid">
  35. <el-input
  36. v-model="queryParams.appid"
  37. placeholder="请输入appid"
  38. clearable
  39. size="small"
  40. @keyup.enter.native="handleQuery"
  41. />
  42. </el-form-item>
  43. <el-form-item label="状态" prop="status">
  44. <el-select
  45. v-model="queryParams.status"
  46. placeholder="请选择状态"
  47. clearable
  48. size="small"
  49. >
  50. <el-option
  51. v-for="item in statusOptions"
  52. :key="item.value"
  53. :label="item.label"
  54. :value="item.value"
  55. />
  56. </el-select>
  57. </el-form-item>
  58. <el-form-item>
  59. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  60. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  61. </el-form-item>
  62. </el-form>
  63. <el-row :gutter="10" class="mb8">
  64. <el-col :span="1.5">
  65. <el-button
  66. type="primary"
  67. plain
  68. icon="el-icon-plus"
  69. size="mini"
  70. @click="handleAdd"
  71. v-hasPermi="['course:playSourceConfig:add']"
  72. >新增</el-button>
  73. </el-col>
  74. <el-col :span="1.5">
  75. <el-button
  76. type="success"
  77. plain
  78. icon="el-icon-edit"
  79. size="mini"
  80. :disabled="single"
  81. @click="handleUpdate"
  82. v-hasPermi="['course:playSourceConfig:edit']"
  83. >修改</el-button>
  84. </el-col>
  85. <el-col :span="1.5">
  86. <el-button
  87. type="danger"
  88. plain
  89. icon="el-icon-delete"
  90. size="mini"
  91. :disabled="multiple"
  92. @click="handleDelete"
  93. v-hasPermi="['course:playSourceConfig:remove']"
  94. >删除</el-button>
  95. </el-col>
  96. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  97. </el-row>
  98. <!-- 开关配置对话框 -->
  99. <el-dialog title="开关配置" :visible.sync="switchDialogVisible" width="500px" class="switch-dialog">
  100. <el-form :model="switchForm" label-width="100px">
  101. <el-form-item label="AppId">
  102. <el-input v-model="switchForm.appId" :disabled="true"></el-input>
  103. </el-form-item>
  104. <el-form-item label="开关状态">
  105. <el-switch
  106. v-model="switchForm.switchStatus"
  107. active-text="开启"
  108. inactive-text="关闭"
  109. active-value="001"
  110. inactive-value="002">
  111. </el-switch>
  112. </el-form-item>
  113. <el-form-item label="配置信息" v-if="switchForm.configInfo">
  114. <el-input
  115. type="textarea"
  116. :rows="4"
  117. v-model="switchForm.configInfo"
  118. :disabled="true">
  119. </el-input>
  120. </el-form-item>
  121. </el-form>
  122. <span slot="footer" class="dialog-footer">
  123. <el-button @click="switchDialogVisible = false">取 消</el-button>
  124. <el-button type="primary" @click="submitSwitchConfig">确 定</el-button>
  125. </span>
  126. </el-dialog>
  127. <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange" border>
  128. <el-table-column type="selection" width="55" align="center" />
  129. <el-table-column label="ID" align="center" prop="id" />
  130. <el-table-column label="名称" align="center" prop="name" />
  131. <el-table-column label="所属公司" align="center" prop="companyId" :formatter="companyNameFormatter"/>
  132. <el-table-column label="图标" align="center" prop="img">
  133. <template slot-scope="scope">
  134. <el-image
  135. style="width: 80px; height: 80px"
  136. :src="scope.row.img"
  137. :preview-src-list="[scope.row.img]">
  138. </el-image>
  139. </template>
  140. </el-table-column>
  141. <el-table-column label="原始ID" align="center" prop="originalId" />
  142. <el-table-column label="appId" align="center" prop="appid" />
  143. <el-table-column label="secret" align="center" prop="secret" />
  144. <el-table-column label="token" align="center" prop="token" />
  145. <el-table-column label="aesKey" align="center" prop="aesKey" />
  146. <el-table-column label="msgDataFormat" align="center" prop="msgDataFormat" />
  147. <el-table-column label="类型" align="center" prop="type">
  148. <template slot-scope="scope">
  149. <dict-tag :options="typesOptions" :value="scope.row.type"/>
  150. </template>
  151. </el-table-column>
  152. <el-table-column label="互医/商城小程序" align="center" prop="isMall" width="80px">
  153. <template slot-scope="scope">
  154. <el-tag prop="isMall" v-for="(item, index) in isMallOptions" v-if="scope.row.isMall==item.dictValue">{{item.dictLabel}}</el-tag>
  155. </template>
  156. </el-table-column>
  157. <el-table-column label="状态" align="center" prop="status" width="100px">
  158. <template slot-scope="scope">
  159. <el-tag
  160. :type="scope.row.status === 0 ? 'success' : scope.row.status === 1 ? 'warning' : 'danger'"
  161. >
  162. {{ getStatusLabel(scope.row.status) }}
  163. </el-tag>
  164. </template>
  165. </el-table-column>
  166. <el-table-column label="创建时间" align="center" prop="createTime" />
  167. <el-table-column label="修改时间" align="center" prop="updateTime" />
  168. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  169. <template slot-scope="scope">
  170. <el-button
  171. size="mini"
  172. type="text"
  173. icon="el-icon-edit"
  174. @click="handleUpdate(scope.row)"
  175. v-hasPermi="['course:playSourceConfig:edit']"
  176. >修改</el-button>
  177. <el-button
  178. size="mini"
  179. type="text"
  180. icon="el-icon-delete"
  181. @click="handleDelete(scope.row)"
  182. v-hasPermi="['course:playSourceConfig:remove']"
  183. >删除</el-button>
  184. <el-button
  185. size="mini"
  186. type="text"
  187. icon="el-icon-setting"
  188. @click="handleSwitchConfig(scope.row)"
  189. >是否展示销售</el-button>
  190. </template>
  191. </el-table-column>
  192. </el-table>
  193. <pagination
  194. v-show="total>0"
  195. :total="total"
  196. :page.sync="queryParams.pageNum"
  197. :limit.sync="queryParams.pageSize"
  198. @pagination="getList"
  199. />
  200. <!-- 添加或修改点播配置对话框 -->
  201. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :before-close="resetOption">
  202. <el-form ref="form" :model="form" :rules="rules" label-width="130px">
  203. <el-form-item label="名称" prop="name">
  204. <el-input v-model="form.name" placeholder="请输入名称" />
  205. </el-form-item>
  206. <el-form-item label="所属公司" prop="companyId">
  207. <el-select
  208. v-model="form.companyId"
  209. filterable
  210. remote
  211. reserve-keyword
  212. placeholder="请输入公司名称搜索"
  213. :remote-method="searchCompanies"
  214. :loading="companySearchLoading"
  215. style="width: 220px"
  216. clearable
  217. size="small"
  218. >
  219. <el-option
  220. v-for="item in companyOptions"
  221. :key="item.dictValue"
  222. :label="item.dictLabel"
  223. :value="item.dictValue"
  224. />
  225. </el-select>
  226. </el-form-item>
  227. <el-form-item label="可查看设置公司" prop="setCompanyIdList">
  228. <el-select
  229. v-model="form.setCompanyIdList"
  230. filterable
  231. multiple
  232. remote
  233. reserve-keyword
  234. placeholder="请输入公司名称搜索"
  235. :remote-method="searchCompanies"
  236. :loading="companySearchLoading"
  237. style="width: 220px"
  238. clearable
  239. size="small"
  240. >
  241. <el-option
  242. v-for="item in companyOptions"
  243. :key="item.dictValue"
  244. :label="item.dictLabel"
  245. :value="item.dictValue"
  246. />
  247. </el-select>
  248. </el-form-item>
  249. <el-form-item label="是否是互医/商城小程序" prop="isMall">
  250. <el-select
  251. v-model="form.isMall"
  252. style="width: 220px"
  253. clearable
  254. size="small"
  255. >
  256. <el-option
  257. v-for="item in isMallOptions"
  258. :key="item.dictValue"
  259. :label="item.dictLabel"
  260. :value="item.dictValue"
  261. />
  262. </el-select>
  263. </el-form-item>
  264. <el-form-item label="状态" prop="status">
  265. <el-select
  266. v-model="form.status"
  267. placeholder="请选择状态"
  268. style="width: 220px"
  269. clearable
  270. size="small"
  271. >
  272. <el-option
  273. v-for="item in statusOptions"
  274. :key="item.value"
  275. :label="item.label"
  276. :value="item.value"
  277. />
  278. </el-select>
  279. </el-form-item>
  280. <el-form-item label="图标" prop="img">
  281. <image-upload v-model="form.img" :file-type='["png", "jpg", "jpeg"]' :limit="1"/>
  282. </el-form-item>
  283. <el-form-item label="类型" prop="type">
  284. <el-select
  285. v-model="form.type"
  286. placeholder="请选择类型">
  287. <el-option
  288. v-for="item in typesOptions"
  289. :key="item.dictValue"
  290. :label="item.dictLabel"
  291. :value="item.dictValue"/>
  292. </el-select>
  293. </el-form-item>
  294. <el-form-item label="原始id" prop="originalId">
  295. <el-input v-model="form.originalId" placeholder="请输入原始id" />
  296. </el-form-item>
  297. <el-form-item label="appid" prop="appid">
  298. <el-input v-model="form.appid" placeholder="请输入appid" />
  299. </el-form-item>
  300. <el-form-item label="secret" prop="secret">
  301. <el-input v-model="form.secret" placeholder="请输入secret" />
  302. </el-form-item>
  303. <el-form-item label="token" prop="token">
  304. <el-input v-model="form.token" placeholder="请输入token" />
  305. </el-form-item>
  306. <el-form-item label="aesKey" prop="aesKey">
  307. <el-input v-model="form.aesKey" placeholder="请输入aesKey" />
  308. </el-form-item>
  309. <el-form-item label="msgDataFormat" prop="msgDataFormat">
  310. <el-input v-model="form.msgDataFormat" placeholder="请输入msgDataFormat" />
  311. </el-form-item>
  312. </el-form>
  313. <div slot="footer" class="dialog-footer">
  314. <el-button type="primary" @click="submitForm">确 定</el-button>
  315. <el-button @click="cancel">取 消</el-button>
  316. </div>
  317. </el-dialog>
  318. </div>
  319. </template>
  320. <script>
  321. import {list, get, update, add, del} from '@/api/course/coursePlaySourceConfig'
  322. import {updateIsTownOn} from "@/api/system/config";
  323. import { allList } from '@/api/company/company'
  324. import { resetForm } from '@/utils/common'
  325. export default {
  326. name: 'CoursePlaySourceConfig',
  327. data() {
  328. return {
  329. switchDialogVisible: false,
  330. // 公司搜索相关
  331. companySearchLoading: false,
  332. companyOptions: [],
  333. formatterCompanyOptions: [],
  334. switchForm: {
  335. appId: '',
  336. switchStatus: '001',
  337. },
  338. queryParams: {
  339. pageNum: 1,
  340. pageSize: 10,
  341. name: null,
  342. appid: null,
  343. status: null
  344. },
  345. showSearch: true,
  346. single: true,
  347. multiple: true,
  348. ids: [],
  349. loading: false,
  350. list: [],
  351. total: 0,
  352. typesOptions: [],
  353. statusOptions: [
  354. {
  355. label: "正常",
  356. value: 0
  357. },
  358. {
  359. label: "半封禁",
  360. value: 1
  361. },
  362. {
  363. label: "封禁",
  364. value: 2
  365. }
  366. ],
  367. isMallOptions:[
  368. {
  369. dictLabel: "是",
  370. dictValue: 1
  371. },
  372. {
  373. dictLabel: "否",
  374. dictValue: 0
  375. }
  376. ],
  377. title: null,
  378. open: false,
  379. form: {
  380. setCompanyIdList: []
  381. },
  382. rules: {
  383. name: [
  384. { required: true, message: "名称不能为空", trigger: "blur" }
  385. ],
  386. // companyId: [
  387. // { required: true, message: "所属公司不能为空", trigger: "blur" }
  388. // ],
  389. appid: [
  390. { required: true, message: "appid不能为空", trigger: "blur" }
  391. ],
  392. img: [
  393. { required: true, message: "图标不能为空", trigger: "blur" }
  394. ],
  395. type: [
  396. { required: true, message: "类型不能为空", trigger: "blur" }
  397. ],
  398. originalId: [
  399. { required: true, message: "原始id不能为空", trigger: "blur" }
  400. ],
  401. secret: [
  402. { required: true, message: "secret不能为空", trigger: "blur" }
  403. ],
  404. token: [
  405. { required: true, message: "token不能为空", trigger: "blur" }
  406. ],
  407. aesKey: [
  408. { required: true, message: "aesKey不能为空", trigger: "blur" }
  409. ],
  410. msgDataFormat: [
  411. { required: true, message: "msgDataFormat不能为空", trigger: "blur" }
  412. ]
  413. }
  414. }
  415. },
  416. created() {
  417. this.getDicts("play_source_type").then(response => {
  418. this.typesOptions = response.data.map(item => {
  419. return {
  420. ...item,
  421. listClass: 'primary'}
  422. })
  423. });
  424. //初始化formatterCompanyOptions
  425. allList().then(e => {
  426. this.formatterCompanyOptions = e.rows;
  427. });
  428. this.getList();
  429. },
  430. methods: {
  431. resetForm,
  432. resetOption(){
  433. console.log(1)
  434. this.companyOptions = [];
  435. this.open = false;
  436. },
  437. // 处理开关配置
  438. handleSwitchConfig(row) {
  439. this.switchForm.appId = row.appid;
  440. this.switchForm.switchStatus = "001"; // 默认关闭状态
  441. // 调用接口获取开关状态
  442. this.getSwitchConfig(row.appid);
  443. this.switchDialogVisible = true;
  444. },
  445. /** 搜索公司 */
  446. searchCompanies(query) {
  447. this.companySearchLoading = true;
  448. allList().then(response => {
  449. this.companyOptions = response.rows;
  450. if (query) {
  451. this.companyOptions = this.companyOptions.filter(item =>
  452. item.dictLabel.includes(query)
  453. );
  454. }
  455. this.companySearchLoading = false;
  456. }).catch(()=>{
  457. this.companySearchLoading = false;
  458. });
  459. },
  460. companyNameFormatter(row){
  461. let company = this.formatterCompanyOptions.filter(item => item.dictValue === row.companyId)[0];
  462. return company ? company.dictLabel : '';
  463. },
  464. // 获取开关配置
  465. getSwitchConfig(appId) {
  466. const params = {
  467. appId: this.switchForm.appId
  468. };
  469. updateIsTownOn(params).then(response=>{
  470. if (response.code === 200) {
  471. if ( response.date){
  472. this.switchForm.switchStatus = response.date;
  473. }
  474. } else {
  475. this.$message.error('获取配置失败: ' + response.msg);
  476. }
  477. }).catch(error => {
  478. this.$message.error('请求失败: ' + error.message);
  479. });
  480. },
  481. // 提交开关配置
  482. submitSwitchConfig() {
  483. const params = {
  484. appId: this.switchForm.appId,
  485. bock: this.switchForm.switchStatus
  486. };
  487. updateIsTownOn(params).then(response=>{
  488. if (response.code === 200) {
  489. this.$message.success('配置更新成功');
  490. this.switchDialogVisible = false;
  491. } else {
  492. this.$message.error('更新失败: ' + response.msg);
  493. }
  494. })
  495. },
  496. getList() {
  497. this.loading = true;
  498. list(this.queryParams).then(response => {
  499. this.list = response.rows;
  500. this.total = response.total;
  501. this.loading = false;
  502. });
  503. },
  504. handleQuery() {
  505. this.queryParams.pageNum = 1;
  506. this.getList();
  507. },
  508. resetQuery() {
  509. this.resetForm("queryForm");
  510. this.getList();
  511. },
  512. handleAdd() {
  513. this.reset()
  514. this.open = true
  515. this.form.isMall = 0;
  516. this.title = "添加小程序配置"
  517. },
  518. handleUpdate(row) {
  519. this.reset()
  520. const id = row.id || this.ids
  521. get(id).then(response => {
  522. this.form = {
  523. ...response.data,
  524. type: response.data.type.toString()
  525. }
  526. if(!!this.form.setCompanyIds){
  527. this.$set(
  528. this.form,
  529. "setCompanyIdList",
  530. this.form.setCompanyIds.split(",").map(str => parseInt(str, 10))
  531. );
  532. // this.form.setCompanyIdList = this.form.setCompanyIds.split(",").map(str => parseInt(str, 10));
  533. }
  534. console.log( this.form);
  535. this.searchCompanies("");
  536. this.open = true
  537. this.title = "修改小程序配置"
  538. })
  539. },
  540. handleDelete(row) {
  541. const id = row.id || this.ids
  542. this.$confirm('是否确认删除小程序配置编号为"' + id + '"的数据项?', "警告", {
  543. confirmButtonText: "确定",
  544. cancelButtonText: "取消",
  545. type: "warning"
  546. }).then(function() {
  547. return del(id);
  548. }).then(() => {
  549. this.getList();
  550. this.msgSuccess("删除成功");
  551. }).catch(() => {});
  552. },
  553. handleSelectionChange(selection) {
  554. this.ids = selection.map(item => item.id)
  555. this.single = selection.length!==1
  556. this.multiple = !selection.length
  557. },
  558. submitForm() {
  559. this.$refs["form"].validate(valid => {
  560. if (valid) {
  561. if(!!this.form.setCompanyIdList && this.form.setCompanyIdList.length > 0){
  562. this.form.setCompanyIds = this.form.setCompanyIdList.join(',')
  563. }else{
  564. this.form.setCompanyIds = "";
  565. }
  566. console.log(this.form);
  567. if (this.form.id != null) {
  568. update(this.form).then(response => {
  569. const {code, msg} = response
  570. if (code !== 200) {
  571. this.msgError(msg)
  572. return
  573. }
  574. this.msgSuccess("修改成功");
  575. this.open = false;
  576. this.getList();
  577. });
  578. } else {
  579. add(this.form).then(response => {
  580. const {code, msg} = response
  581. if (code !== 200) {
  582. this.msgError(msg)
  583. return
  584. }
  585. this.msgSuccess("新增成功");
  586. this.open = false;
  587. this.getList();
  588. });
  589. }
  590. }
  591. });
  592. },
  593. cancel() {
  594. this.open = false;
  595. this.reset();
  596. },
  597. reset() {
  598. this.form = {
  599. id: null,
  600. name: null,
  601. appid: null,
  602. secret: null,
  603. img: null,
  604. originalId: null,
  605. setCompanyIdList: [],
  606. token: 'cbnd7lJvkripVOpyTFAna6NAWCxCrvC',
  607. aesKey: 'HlEiBB55eaWUaeBVAQO3cWKWPYv1vOVQSq7nFNICw4E',
  608. msgDataFormat: 'JSON',
  609. type: '1',
  610. status: 0
  611. }
  612. this.resetForm("form");
  613. },
  614. getStatusLabel(status) {
  615. const statusMap = {
  616. 0: '正常',
  617. 1: '半封禁',
  618. 2: '封禁'
  619. };
  620. return statusMap[status] || '未知';
  621. }
  622. },
  623. }
  624. </script>
  625. <style scoped>
  626. </style>