index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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 === -1 ? 'info' : 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="createDeptId">
  228. <treeselect v-model="form.createDeptId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" :disabled="(username !== 'admin' && title === '修改小程序配置')" />
  229. </el-form-item>
  230. <el-form-item label="是否是互医/商城小程序" prop="isMall">
  231. <el-select
  232. v-model="form.isMall"
  233. style="width: 220px"
  234. clearable
  235. size="small"
  236. >
  237. <el-option
  238. v-for="item in isMallOptions"
  239. :key="item.dictValue"
  240. :label="item.dictLabel"
  241. :value="item.dictValue"
  242. />
  243. </el-select>
  244. </el-form-item>
  245. <el-form-item label="状态" prop="status">
  246. <el-select
  247. v-model="form.status"
  248. placeholder="请选择状态"
  249. style="width: 220px"
  250. clearable
  251. size="small"
  252. >
  253. <el-option
  254. v-for="item in statusOptions"
  255. :key="item.value"
  256. :label="item.label"
  257. :value="item.value"
  258. />
  259. </el-select>
  260. </el-form-item>
  261. <el-form-item label="图标" prop="img">
  262. <image-upload v-model="form.img" :file-type='["png", "jpg", "jpeg"]' :limit="1"/>
  263. </el-form-item>
  264. <el-form-item label="类型" prop="type">
  265. <el-select
  266. v-model="form.type"
  267. placeholder="请选择类型">
  268. <el-option
  269. v-for="item in typesOptions"
  270. :key="item.dictValue"
  271. :label="item.dictLabel"
  272. :value="item.dictValue"/>
  273. </el-select>
  274. </el-form-item>
  275. <el-form-item label="原始id" prop="originalId">
  276. <el-input v-model="form.originalId" placeholder="请输入原始id" />
  277. </el-form-item>
  278. <el-form-item label="appid" prop="appid">
  279. <el-input v-model="form.appid" placeholder="请输入appid" />
  280. </el-form-item>
  281. <el-form-item label="secret" prop="secret">
  282. <el-input v-model="form.secret" placeholder="请输入secret" />
  283. </el-form-item>
  284. <el-form-item label="token" prop="token">
  285. <el-input v-model="form.token" placeholder="请输入token" />
  286. </el-form-item>
  287. <el-form-item label="aesKey" prop="aesKey">
  288. <el-input v-model="form.aesKey" placeholder="请输入aesKey" />
  289. </el-form-item>
  290. <el-form-item label="msgDataFormat" prop="msgDataFormat">
  291. <el-input v-model="form.msgDataFormat" placeholder="请输入msgDataFormat" />
  292. </el-form-item>
  293. </el-form>
  294. <div slot="footer" class="dialog-footer">
  295. <el-button type="primary" @click="submitForm">确 定</el-button>
  296. <el-button @click="cancel">取 消</el-button>
  297. </div>
  298. </el-dialog>
  299. </div>
  300. </template>
  301. <script>
  302. import {list, get, update, add, del} from '@/api/course/coursePlaySourceConfig'
  303. import {updateIsTownOn} from "@/api/system/config";
  304. import { allList } from '@/api/company/company'
  305. import { resetForm } from '@/utils/common'
  306. import Treeselect from "@riophae/vue-treeselect";
  307. import {listDept} from "@/api/system/dept";
  308. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  309. import { getUserProfile } from "@/api/system/user";
  310. export default {
  311. name: 'CoursePlaySourceConfig',
  312. components: {Treeselect},
  313. data() {
  314. return {
  315. authOptions:[
  316. {
  317. dictLabel: "食品",
  318. dictValue: 0
  319. },
  320. {
  321. dictLabel: "药品",
  322. dictValue: 1
  323. }
  324. ],
  325. username:null,
  326. // 部门树选项
  327. deptOptions: [],
  328. switchDialogVisible: false,
  329. // 公司搜索相关
  330. companySearchLoading: false,
  331. companyOptions: [],
  332. formatterCompanyOptions: [],
  333. switchForm: {
  334. appId: '',
  335. switchStatus: '001',
  336. },
  337. queryParams: {
  338. pageNum: 1,
  339. pageSize: 10,
  340. name: null,
  341. appid: null,
  342. status: null
  343. },
  344. showSearch: true,
  345. single: true,
  346. multiple: true,
  347. ids: [],
  348. loading: false,
  349. list: [],
  350. total: 0,
  351. typesOptions: [],
  352. statusOptions: [
  353. {
  354. label: "待审核",
  355. value: -1
  356. },
  357. {
  358. label: "正常",
  359. value: 0
  360. },
  361. {
  362. label: "半封禁",
  363. value: 1
  364. },
  365. {
  366. label: "封禁",
  367. value: 2
  368. }
  369. ],
  370. isMallOptions:[
  371. {
  372. dictLabel: "是",
  373. dictValue: 1
  374. },
  375. {
  376. dictLabel: "否",
  377. dictValue: 0
  378. }
  379. ],
  380. title: null,
  381. open: false,
  382. form: {isMall:0},
  383. rules: {
  384. name: [
  385. { required: true, message: "名称不能为空", trigger: "blur" }
  386. ],
  387. // companyId: [
  388. // { required: true, message: "所属公司不能为空", trigger: "blur" }
  389. // ],
  390. appid: [
  391. { required: true, message: "appid不能为空", trigger: "blur" }
  392. ],
  393. img: [
  394. { required: true, message: "图标不能为空", trigger: "blur" }
  395. ],
  396. type: [
  397. { required: true, message: "类型不能为空", trigger: "blur" }
  398. ],
  399. originalId: [
  400. { required: true, message: "原始id不能为空", trigger: "blur" }
  401. ],
  402. secret: [
  403. { required: true, message: "secret不能为空", trigger: "blur" }
  404. ],
  405. token: [
  406. { required: true, message: "token不能为空", trigger: "blur" }
  407. ],
  408. aesKey: [
  409. { required: true, message: "aesKey不能为空", trigger: "blur" }
  410. ],
  411. msgDataFormat: [
  412. { required: true, message: "msgDataFormat不能为空", trigger: "blur" }
  413. ]
  414. }
  415. }
  416. },
  417. created() {
  418. this.getDicts("play_source_type").then(response => {
  419. this.typesOptions = response.data.map(item => {
  420. return {
  421. ...item,
  422. listClass: 'primary'}
  423. })
  424. });
  425. //初始化formatterCompanyOptions
  426. allList().then(e => {
  427. this.formatterCompanyOptions = e.rows;
  428. });
  429. this.getList();
  430. listDept().then(response => {
  431. this.deptOptions = this.handleTree(response.data, "deptId");
  432. });
  433. getUserProfile().then(response => {
  434. const data = response.data;
  435. this.username = data.userName;
  436. });
  437. },
  438. methods: {
  439. resetForm,
  440. resetOption(){
  441. console.log(1)
  442. this.companyOptions = [];
  443. this.open = false;
  444. },
  445. /** 转换部门数据结构 */
  446. normalizer(node) {
  447. if (node.hasOwnProperty('id') && !node.hasOwnProperty('deptId')) {
  448. return {
  449. id: node.id,
  450. label: this.getDeptNameById(node.id) || '未知部门',
  451. children: node.children || []
  452. };
  453. }
  454. if (node.children && !node.children.length) {
  455. delete node.children;
  456. }
  457. return {
  458. id: node.deptId,
  459. label: node.deptName,
  460. children: node.children
  461. };
  462. },
  463. getDeptNameById(targetId) {
  464. const deptOptions =this.deptOptions
  465. console.log("text:"+JSON.stringify(deptOptions))
  466. for (let i = 0; i < deptOptions.length; i++) {
  467. const dept = deptOptions[i];
  468. if (dept.deptId === targetId) {
  469. return dept.deptName;
  470. }
  471. }
  472. return '未知部门';
  473. },
  474. // 处理开关配置
  475. handleSwitchConfig(row) {
  476. this.switchForm.appId = row.appid;
  477. this.switchForm.switchStatus = "001"; // 默认关闭状态
  478. // 调用接口获取开关状态
  479. this.getSwitchConfig(row.appid);
  480. this.switchDialogVisible = true;
  481. },
  482. /** 搜索公司 */
  483. searchCompanies(query) {
  484. this.companySearchLoading = true;
  485. allList().then(response => {
  486. this.companyOptions = response.rows;
  487. if (query) {
  488. this.companyOptions = this.companyOptions.filter(item =>
  489. item.dictLabel.includes(query)
  490. );
  491. }
  492. this.companySearchLoading = false;
  493. }).catch(()=>{
  494. this.companySearchLoading = false;
  495. });
  496. },
  497. companyNameFormatter(row){
  498. let company = this.formatterCompanyOptions.filter(item => item.dictValue === row.companyId)[0];
  499. return company ? company.dictLabel : '';
  500. },
  501. departmentNameFormatter(row) {
  502. // 容错处理:检查必要参数
  503. if (!this.deptOptions || !this.deptOptions.length || !row.deptId) {
  504. return '';
  505. }
  506. // 使用 deptId 匹配(与表格 prop 保持一致)
  507. const targetId = String(row.deptId);
  508. // 递归查找树形结构中的部门
  509. const findDept = (depts) => {
  510. for (const dept of depts) {
  511. // 先检查当前节点
  512. if (String(dept.deptId) === targetId) {
  513. return dept;
  514. }
  515. // 如果有子节点,递归查找
  516. if (dept.children && dept.children.length > 0) {
  517. const found = findDept(dept.children);
  518. if (found) return found;
  519. }
  520. }
  521. return null;
  522. };
  523. const dept = findDept(this.deptOptions);
  524. return dept?.deptName || '';
  525. },
  526. // 获取开关配置
  527. getSwitchConfig(appId) {
  528. const params = {
  529. appId: this.switchForm.appId
  530. };
  531. updateIsTownOn(params).then(response=>{
  532. if (response.code === 200) {
  533. if ( response.date){
  534. this.switchForm.switchStatus = response.date;
  535. }
  536. } else {
  537. this.$message.error('获取配置失败: ' + response.msg);
  538. }
  539. }).catch(error => {
  540. this.$message.error('请求失败: ' + error.message);
  541. });
  542. },
  543. // 提交开关配置
  544. submitSwitchConfig() {
  545. const params = {
  546. appId: this.switchForm.appId,
  547. bock: this.switchForm.switchStatus
  548. };
  549. updateIsTownOn(params).then(response=>{
  550. if (response.code === 200) {
  551. this.$message.success('配置更新成功');
  552. this.switchDialogVisible = false;
  553. } else {
  554. this.$message.error('更新失败: ' + response.msg);
  555. }
  556. })
  557. },
  558. getList() {
  559. this.loading = true;
  560. list(this.queryParams).then(response => {
  561. this.list = response.rows;
  562. this.total = response.total;
  563. this.loading = false;
  564. });
  565. },
  566. handleQuery() {
  567. this.queryParams.pageNum = 1;
  568. this.getList();
  569. },
  570. resetQuery() {
  571. this.resetForm("queryForm");
  572. this.getList();
  573. },
  574. handleAdd() {
  575. this.reset()
  576. this.open = true
  577. this.form.isMall = 0;
  578. this.title = "添加小程序配置"
  579. },
  580. handleUpdate(row) {
  581. this.reset()
  582. const id = row.id || this.ids
  583. get(id).then(response => {
  584. this.form = {
  585. ...response.data,
  586. type: response.data.type.toString()
  587. }
  588. this.searchCompanies("");
  589. this.open = true
  590. this.title = "修改小程序配置"
  591. })
  592. },
  593. handleDelete(row) {
  594. const id = row.id || this.ids
  595. this.$confirm('是否确认删除小程序配置编号为"' + id + '"的数据项?', "警告", {
  596. confirmButtonText: "确定",
  597. cancelButtonText: "取消",
  598. type: "warning"
  599. }).then(function() {
  600. return del(id);
  601. }).then(() => {
  602. this.getList();
  603. this.msgSuccess("删除成功");
  604. }).catch(() => {});
  605. },
  606. handleSelectionChange(selection) {
  607. this.ids = selection.map(item => item.id)
  608. this.single = selection.length!==1
  609. this.multiple = !selection.length
  610. },
  611. submitForm() {
  612. this.$refs["form"].validate(valid => {
  613. if (valid) {
  614. if (this.form.id != null) {
  615. update(this.form).then(response => {
  616. const {code, msg} = response
  617. if (code !== 200) {
  618. this.msgError(msg)
  619. return
  620. }
  621. this.msgSuccess("修改成功");
  622. this.open = false;
  623. this.getList();
  624. });
  625. } else {
  626. add(this.form).then(response => {
  627. const {code, msg} = response
  628. if (code !== 200) {
  629. this.msgError(msg)
  630. return
  631. }
  632. this.msgSuccess("新增成功");
  633. this.open = false;
  634. this.getList();
  635. });
  636. }
  637. }
  638. });
  639. },
  640. cancel() {
  641. this.open = false;
  642. this.reset();
  643. },
  644. reset() {
  645. this.form = {
  646. id: null,
  647. name: null,
  648. appid: null,
  649. secret: null,
  650. img: null,
  651. originalId: null,
  652. token: 'Ncbnd7lJvkripVOpyTFAna6NAWCxCrvC',
  653. aesKey: 'HlEiBB55eaWUaeBVAQO3cWKWPYv1vOVQSq7nFNICw4E',
  654. msgDataFormat: 'JSON',
  655. type: '1',
  656. isMall: 0,
  657. status: 0
  658. }
  659. this.resetForm("form");
  660. },
  661. getStatusLabel(status) {
  662. const statusMap = {
  663. '-1': '待审核',
  664. '0': '正常',
  665. '1': '半封禁',
  666. '2': '封禁'
  667. };
  668. return statusMap[status] || '未知';
  669. }
  670. },
  671. }
  672. </script>
  673. <style scoped>
  674. </style>