info.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <template>
  2. <div class="content-box">
  3. <div class="header">基本信息</div>
  4. <div class="scroll">
  5. <!-- 学校基本信息区域 -->
  6. <div class="title">
  7. <div class="title_text">学校基本信息</div>
  8. <el-button type="primary" v-if="showSchool" @click="saveSchool"
  9. >保存</el-button
  10. >
  11. <el-button type="primary" plain v-if="showSchool" @click="cancelSchool"
  12. >取消</el-button
  13. >
  14. <el-button type="primary" v-if="!showSchool" @click="editSchool"
  15. >修改</el-button
  16. >
  17. </div>
  18. <div class="info">
  19. 学校编码:
  20. <span v-if="!showSchool">{{ schoolCode || "无" }}</span>
  21. <el-input
  22. v-if="showSchool"
  23. style="width: 150px"
  24. v-model="schoolCode"
  25. placeholder="请输入学校编码"
  26. />
  27. </div>
  28. <div class="info">
  29. 学校名称:
  30. <span v-if="!showSchool">{{ schoolName || "无" }}</span>
  31. <el-input
  32. v-if="showSchool"
  33. style="width: 150px"
  34. v-model="schoolName"
  35. placeholder="请输入学校名称"
  36. />
  37. </div>
  38. <div class="info info2">
  39. <span class="info_key">校徽:</span>
  40. <el-upload
  41. class="avatar-uploader"
  42. action="#"
  43. :auto-upload="false"
  44. :on-change="handleChange"
  45. ref="upload"
  46. :limit="1"
  47. :on-exceed="handleExceed"
  48. >
  49. <el-button class="info_btn" type="primary" plain v-if="showSchool">
  50. 点击上传
  51. </el-button>
  52. </el-upload>
  53. <img class="info_img" :src="schoolImg" fit="cover" />
  54. <div class="info_img" v-if="!schoolImg">暂无图片</div>
  55. <!-- <div class="icon_delete" v-if="showSchool" @click="handleDelete">
  56. <el-icon>
  57. <Delete />
  58. </el-icon>
  59. </div> -->
  60. </div>
  61. <div class="info info2">
  62. <span class="info_key">管理平台logo:</span>
  63. <el-upload
  64. class="avatar-uploader"
  65. action="#"
  66. :auto-upload="false"
  67. :on-change="handleChange2"
  68. ref="upload2"
  69. :limit="1"
  70. :on-exceed="handleExceed2"
  71. >
  72. <el-button class="info_btn" type="primary" plain v-if="showSchool">
  73. 点击上传
  74. </el-button>
  75. </el-upload>
  76. <img class="info_img" :src="logoImg" fit="cover" />
  77. <div class="info_img" v-if="!logoImg">暂无图片</div>
  78. <!-- <div class="icon_delete" v-if="showSchool" @click="handleDelete">
  79. <el-icon>
  80. <Delete />
  81. </el-icon>
  82. </div> -->
  83. </div>
  84. <div class="info">在校学生人数:{{ studentCount }}</div>
  85. <!-- 公众号信息区域 -->
  86. <div class="title">
  87. <div class="title_text">公众号</div>
  88. <el-button type="primary" v-if="showApp" @click="saveApp"
  89. >保存</el-button
  90. >
  91. <el-button type="primary" plain v-if="showApp" @click="cancelApp"
  92. >取消</el-button
  93. >
  94. <el-button type="primary" v-if="!showApp" @click="editApp"
  95. >修改</el-button
  96. >
  97. </div>
  98. <div class="info">
  99. 名称:
  100. <span v-if="!showApp">{{ appName || "无" }}</span>
  101. <el-input
  102. v-if="showApp"
  103. style="width: 200px"
  104. v-model="appName"
  105. placeholder="请输入公众号名称"
  106. />
  107. </div>
  108. <div class="info">
  109. APPID:
  110. <span v-if="!showApp">{{ appAppid || "无" }}</span>
  111. <el-input
  112. v-if="showApp"
  113. style="width: 200px"
  114. v-model="appAppid"
  115. placeholder="请输入APPID"
  116. />
  117. </div>
  118. <div class="info">
  119. 原始ID: <span v-if="!showApp">{{ appOldId || "无" }}</span>
  120. <el-input
  121. v-if="showApp"
  122. style="width: 200px"
  123. v-model="appOldId"
  124. placeholder="请输入原始ID"
  125. />
  126. </div>
  127. </div>
  128. </div>
  129. </template>
  130. <script setup>
  131. import {
  132. ref,
  133. reactive,
  134. watch,
  135. nextTick,
  136. onBeforeMount,
  137. onUnmounted,
  138. } from "vue";
  139. import COS from "cos-js-sdk-v5";
  140. import { useRouter } from "vue-router";
  141. import { ElMessage, ElMessageBox, genFileId } from "element-plus";
  142. import { Camera } from "@element-plus/icons-vue";
  143. import { dayjs } from "element-plus";
  144. import lodash from "lodash";
  145. import eds from "@/utils/eds.js";
  146. import axios from "axios";
  147. import { useStore } from "vuex";
  148. const store = useStore();
  149. const api = ref("");
  150. const router = useRouter();
  151. const infoId = ref(); // 基本信息id
  152. // 学校编码
  153. const schoolCode = ref(4851511515);
  154. // 学校名称
  155. const schoolName = ref("万载县第三中学");
  156. const studentCount=ref() // 学校学生
  157. // 校徽图片地址
  158. const schoolImg = ref();
  159. const upload = ref();
  160. // 管理平台logo图片地址
  161. const logoImg = ref("");
  162. const upload2 = ref();
  163. // 公众号名称
  164. const appName = ref("万载县第三中学");
  165. // 公众号appid
  166. const appAppid = ref("wxd87cbe1db0437303");
  167. // 公众号原始id
  168. const appOldId = ref("gh_aba119389adf");
  169. // 学校基本信息展示编辑切换
  170. const showSchool = ref(false);
  171. // 公众号信息展示编辑切换
  172. const showApp = ref(false);
  173. // 基本信息数据
  174. const getList = async () => {
  175. let data = {
  176. // managerId: sessionStorage.getItem("token"),
  177. };
  178. let res = await axios({
  179. method: "get",
  180. url: api.value + "/wanzai/api/smartSchool/querySmartSchool",
  181. headers: {
  182. token: sessionStorage.getItem("token"),
  183. user_head: sessionStorage.getItem("userhead"),
  184. },
  185. // params: data,
  186. });
  187. // console.log(res,JSON.parse(eds.decryptDes(res.data.data)), "学校基本信息");
  188. if (res.data.code == 200) {
  189. schoolCode.value = JSON.parse(eds.decryptDes(res.data.data)).schoolCode;
  190. schoolImg.value = JSON.parse(eds.decryptDes(res.data.data)).schoolBadge;
  191. schoolName.value = JSON.parse(eds.decryptDes(res.data.data)).name;
  192. studentCount.value = JSON.parse(eds.decryptDes(res.data.data)).studentCount;
  193. logoImg.value = JSON.parse(eds.decryptDes(res.data.data)).logoImage;
  194. appName.value = JSON.parse(eds.decryptDes(res.data.data)).officialName;
  195. appAppid.value = JSON.parse(eds.decryptDes(res.data.data)).appid;
  196. appOldId.value = JSON.parse(eds.decryptDes(res.data.data)).originalId;
  197. infoId.value = JSON.parse(eds.decryptDes(res.data.data)).id;
  198. } else {
  199. // loading.value = false;
  200. if(res.data.message=='登录凭证已过期,请重新登录'){
  201. router.push({
  202. path: `/login`,
  203. });
  204. }
  205. ElMessage({
  206. type: "error",
  207. showClose: true,
  208. message: res.data.message,
  209. center: true,
  210. });
  211. }
  212. };
  213. // 学校信息修改按钮回调
  214. const editSchool = () => {
  215. showSchool.value = true;
  216. };
  217. // 学校信息保存按钮回调
  218. const saveSchool = async () => {
  219. let data = {
  220. id: infoId.value,
  221. schoolCode: schoolCode.value,
  222. name: schoolName.value,
  223. schoolBadge: schoolImg.value,
  224. logoImage: logoImg.value,
  225. officialName: appName.value,
  226. appid: appAppid.value,
  227. originalId: appOldId.value,
  228. };
  229. let res = await axios({
  230. method: "post",
  231. url: api.value + "/wanzai/api/smartSchool/updateSmartSchoolById",
  232. headers: {
  233. token: sessionStorage.getItem("token"),
  234. user_head: sessionStorage.getItem("userhead"),
  235. },
  236. data: data,
  237. });
  238. console.log(res, "修改成功");
  239. if (res.data.code == 200) {
  240. showSchool.value = false;
  241. getList();
  242. ElMessage({
  243. type: "success",
  244. showClose: true,
  245. message: res.data.message,
  246. center: true,
  247. });
  248. } else {
  249. ElMessage({
  250. type: "error",
  251. showClose: true,
  252. message: res.data.message,
  253. center: true,
  254. });
  255. }
  256. };
  257. // 学校信息取消按钮回调
  258. const cancelSchool = () => {
  259. showSchool.value = false;
  260. getList();
  261. };
  262. // 公众号修改按钮回调
  263. const editApp = () => {
  264. showApp.value = true;
  265. };
  266. // 公众号保存按钮回调
  267. const saveApp = async () => {
  268. let data = {
  269. id: infoId.value,
  270. schoolCode: schoolCode.value,
  271. name: schoolName.value,
  272. schoolBadge: schoolImg.value,
  273. logoImage: logoImg.value,
  274. officialName: appName.value,
  275. appid: appAppid.value,
  276. originalId: appOldId.value,
  277. };
  278. let res = await axios({
  279. method: "post",
  280. url: api.value + "/wanzai/api/smartSchool/updateSmartSchoolById",
  281. headers: {
  282. token: sessionStorage.getItem("token"),
  283. user_head: sessionStorage.getItem("userhead"),
  284. },
  285. data: data,
  286. });
  287. console.log(res, "修改成功");
  288. if (res.data.code == 200) {
  289. showApp.value = false;
  290. getList();
  291. ElMessage({
  292. type: "success",
  293. showClose: true,
  294. message: res.data.message,
  295. center: true,
  296. });
  297. } else {
  298. ElMessage({
  299. type: "error",
  300. showClose: true,
  301. message: res.data.message,
  302. center: true,
  303. });
  304. }
  305. };
  306. // 公众号取消按钮回调
  307. const cancelApp = () => {
  308. showApp.value = false;
  309. getList();
  310. };
  311. // 删除图标按钮回调
  312. const handleDelete = () => {
  313. console.log("删除图片");
  314. };
  315. // 校徽图上传(------------------------------------------------------)
  316. const handleChange = (file, fileLists) => {
  317. console.log(file, "file11111");
  318. if (file.raw.type == "image/jpeg" || file.raw.type == "image/png") {
  319. if (file.size / 1024 > 100) {
  320. ElMessage.error("图片的大小不能超过100Kb!");
  321. } else {
  322. if (file.raw) {
  323. const cos = new COS({
  324. SecretId: "AKIDCPVZdcWIxgHpy5FYxVyPiqkZGrhdXUBg",
  325. SecretKey: "NkyCN3cz97qKaeXLvHOGxOcdS8f184pL",
  326. SecurityToken: "1306339220",
  327. Bucket: "wanzai-1306339220",
  328. Region: "ap-shanghai",
  329. });
  330. const files = file.raw;
  331. console.log(files, "files文件");
  332. const key = file.name; // 设置上传到 COS 后的文件名
  333. cos.putObject(
  334. {
  335. Bucket: "wanzai-1306339220",
  336. Region: "ap-shanghai",
  337. Key: key,
  338. Body: files,
  339. onProgress: function (progressData) {
  340. console.log(JSON.stringify(progressData));
  341. },
  342. },
  343. function (err, data) {
  344. if (err) {
  345. console.error(err, "请求失败");
  346. } else {
  347. console.log(data, "请求成功");
  348. schoolImg.value = "https://" + data.Location;
  349. // 成功
  350. }
  351. }
  352. );
  353. }
  354. }
  355. } else {
  356. ElMessage.error("图片格式必须为JPG/PNG格式!");
  357. }
  358. // ruleForm.coverImg = file.url;
  359. };
  360. // 选中时自动替换上一个文件。
  361. const handleExceed = (files) => {
  362. upload.value.clearFiles();
  363. const file = files[0];
  364. file.uid = genFileId();
  365. upload.value.handleStart(file);
  366. };
  367. // 管理平台logo图上传(------------------------------------------------------)
  368. const handleChange2 = (file, fileLists) => {
  369. console.log(file, "file11111");
  370. if (file.raw.type == "image/jpeg" || file.raw.type == "image/png") {
  371. if (file.size / 1024 > 100) {
  372. ElMessage.error("图片的大小不能超过100Kb!");
  373. } else {
  374. if (file.raw) {
  375. const cos = new COS({
  376. SecretId: "AKIDCPVZdcWIxgHpy5FYxVyPiqkZGrhdXUBg",
  377. SecretKey: "NkyCN3cz97qKaeXLvHOGxOcdS8f184pL",
  378. SecurityToken: "1306339220",
  379. Bucket: "wanzai-1306339220",
  380. Region: "ap-shanghai",
  381. });
  382. const files = file.raw;
  383. console.log(files, "files文件");
  384. const key = file.name; // 设置上传到 COS 后的文件名
  385. cos.putObject(
  386. {
  387. Bucket: "wanzai-1306339220",
  388. Region: "ap-shanghai",
  389. Key: key,
  390. Body: files,
  391. onProgress: function (progressData) {
  392. console.log(JSON.stringify(progressData));
  393. },
  394. },
  395. function (err, data) {
  396. if (err) {
  397. console.error(err, "请求失败");
  398. } else {
  399. console.log(data, "请求成功");
  400. logoImg.value = "https://" + data.Location;
  401. // 成功
  402. }
  403. }
  404. );
  405. }
  406. }
  407. } else {
  408. ElMessage.error("图片格式必须为JPG/PNG格式!");
  409. }
  410. // ruleForm.coverImg = file.url;
  411. };
  412. // 选中时自动替换上一个文件。
  413. const handleExceed2 = (files) => {
  414. upload.value.clearFiles();
  415. const file = files[0];
  416. file.uid = genFileId();
  417. upload.value.handleStart(file);
  418. };
  419. onBeforeMount(async () => {
  420. api.value = store.state.user.api;
  421. getList();
  422. });
  423. </script>
  424. <style scoped lang="scss">
  425. .content-box {
  426. min-width: 1000px;
  427. width: calc(100vw - 260px);
  428. height: calc(100vh - 105px);
  429. margin: 20px auto;
  430. background-color: #fff;
  431. box-shadow: 0px 3px 10px rgba(0, 97, 255, 0.2);
  432. .header {
  433. display: flex;
  434. align-items: center;
  435. padding-left: 32px;
  436. height: 60px;
  437. font-size: 18px;
  438. font-weight: bold;
  439. border-bottom: 1px solid #cccccc;
  440. }
  441. .scroll {
  442. height: calc(100% - 61px);
  443. overflow: auto;
  444. :deep(.el-upload-list) {
  445. display: none;
  446. }
  447. }
  448. .title {
  449. display: flex;
  450. align-items: center;
  451. padding-left: 32px;
  452. height: 70px;
  453. font-size: 20px;
  454. font-weight: bold;
  455. .title_text {
  456. margin-right: 24px;
  457. }
  458. }
  459. .info {
  460. display: flex;
  461. align-items: center;
  462. padding-left: 86px;
  463. min-height: 40px;
  464. .info_img {
  465. display: flex;
  466. justify-content: center;
  467. align-items: center;
  468. margin: 10px 0 26px 0;
  469. width: 96px;
  470. height: 96px;
  471. border-radius: 50%;
  472. background-color: #e5e5e5;
  473. }
  474. .info_key {
  475. align-self: flex-start;
  476. margin-top: 10px;
  477. }
  478. .info_btn {
  479. margin-top: 10px;
  480. }
  481. }
  482. .info2 {
  483. flex-wrap: wrap;
  484. width: 215px;
  485. .icon_delete {
  486. align-self: flex-end;
  487. margin-bottom: 26px;
  488. margin-left: 10px;
  489. cursor: pointer;
  490. }
  491. }
  492. }
  493. </style>