index.vue 19 KB

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