info.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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. ElMessage({
  201. type: "error",
  202. showClose: true,
  203. message: res.data.message,
  204. center: true,
  205. });
  206. }
  207. };
  208. // 学校信息修改按钮回调
  209. const editSchool = () => {
  210. showSchool.value = true;
  211. };
  212. // 学校信息保存按钮回调
  213. const saveSchool = async () => {
  214. let data = {
  215. id: infoId.value,
  216. schoolCode: schoolCode.value,
  217. name: schoolName.value,
  218. schoolBadge: schoolImg.value,
  219. logoImage: logoImg.value,
  220. officialName: appName.value,
  221. appid: appAppid.value,
  222. originalId: appOldId.value,
  223. };
  224. let res = await axios({
  225. method: "post",
  226. url: api.value + "/wanzai/api/smartSchool/updateSmartSchoolById",
  227. headers: {
  228. token: sessionStorage.getItem("token"),
  229. user_head: sessionStorage.getItem("userhead"),
  230. },
  231. data: data,
  232. });
  233. console.log(res, "修改成功");
  234. if (res.data.code == 200) {
  235. showSchool.value = false;
  236. getList();
  237. ElMessage({
  238. type: "success",
  239. showClose: true,
  240. message: res.data.message,
  241. center: true,
  242. });
  243. } else {
  244. ElMessage({
  245. type: "error",
  246. showClose: true,
  247. message: res.data.message,
  248. center: true,
  249. });
  250. }
  251. };
  252. // 学校信息取消按钮回调
  253. const cancelSchool = () => {
  254. showSchool.value = false;
  255. getList();
  256. };
  257. // 公众号修改按钮回调
  258. const editApp = () => {
  259. showApp.value = true;
  260. };
  261. // 公众号保存按钮回调
  262. const saveApp = async () => {
  263. let data = {
  264. id: infoId.value,
  265. schoolCode: schoolCode.value,
  266. name: schoolName.value,
  267. schoolBadge: schoolImg.value,
  268. logoImage: logoImg.value,
  269. officialName: appName.value,
  270. appid: appAppid.value,
  271. originalId: appOldId.value,
  272. };
  273. let res = await axios({
  274. method: "post",
  275. url: api.value + "/wanzai/api/smartSchool/updateSmartSchoolById",
  276. headers: {
  277. token: sessionStorage.getItem("token"),
  278. user_head: sessionStorage.getItem("userhead"),
  279. },
  280. data: data,
  281. });
  282. console.log(res, "修改成功");
  283. if (res.data.code == 200) {
  284. showApp.value = false;
  285. getList();
  286. ElMessage({
  287. type: "success",
  288. showClose: true,
  289. message: res.data.message,
  290. center: true,
  291. });
  292. } else {
  293. ElMessage({
  294. type: "error",
  295. showClose: true,
  296. message: res.data.message,
  297. center: true,
  298. });
  299. }
  300. };
  301. // 公众号取消按钮回调
  302. const cancelApp = () => {
  303. showApp.value = false;
  304. getList();
  305. };
  306. // 删除图标按钮回调
  307. const handleDelete = () => {
  308. console.log("删除图片");
  309. };
  310. // 校徽图上传(------------------------------------------------------)
  311. const handleChange = (file, fileLists) => {
  312. console.log(file, "file11111");
  313. if (file.raw.type == "image/jpeg" || file.raw.type == "image/png") {
  314. if (file.size / 1024 > 100) {
  315. ElMessage.error("图片的大小不能超过100Kb!");
  316. } else {
  317. if (file.raw) {
  318. const cos = new COS({
  319. SecretId: "AKIDCPVZdcWIxgHpy5FYxVyPiqkZGrhdXUBg",
  320. SecretKey: "NkyCN3cz97qKaeXLvHOGxOcdS8f184pL",
  321. SecurityToken: "1306339220",
  322. Bucket: "wanzai-1306339220",
  323. Region: "ap-shanghai",
  324. });
  325. const files = file.raw;
  326. console.log(files, "files文件");
  327. const key = file.name; // 设置上传到 COS 后的文件名
  328. cos.putObject(
  329. {
  330. Bucket: "wanzai-1306339220",
  331. Region: "ap-shanghai",
  332. Key: key,
  333. Body: files,
  334. onProgress: function (progressData) {
  335. console.log(JSON.stringify(progressData));
  336. },
  337. },
  338. function (err, data) {
  339. if (err) {
  340. console.error(err, "请求失败");
  341. } else {
  342. console.log(data, "请求成功");
  343. schoolImg.value = "https://" + data.Location;
  344. // 成功
  345. }
  346. }
  347. );
  348. }
  349. }
  350. } else {
  351. ElMessage.error("图片格式必须为JPG/PNG格式!");
  352. }
  353. // ruleForm.coverImg = file.url;
  354. };
  355. // 选中时自动替换上一个文件。
  356. const handleExceed = (files) => {
  357. upload.value.clearFiles();
  358. const file = files[0];
  359. file.uid = genFileId();
  360. upload.value.handleStart(file);
  361. };
  362. // 管理平台logo图上传(------------------------------------------------------)
  363. const handleChange2 = (file, fileLists) => {
  364. console.log(file, "file11111");
  365. if (file.raw.type == "image/jpeg" || file.raw.type == "image/png") {
  366. if (file.size / 1024 > 100) {
  367. ElMessage.error("图片的大小不能超过100Kb!");
  368. } else {
  369. if (file.raw) {
  370. const cos = new COS({
  371. SecretId: "AKIDCPVZdcWIxgHpy5FYxVyPiqkZGrhdXUBg",
  372. SecretKey: "NkyCN3cz97qKaeXLvHOGxOcdS8f184pL",
  373. SecurityToken: "1306339220",
  374. Bucket: "wanzai-1306339220",
  375. Region: "ap-shanghai",
  376. });
  377. const files = file.raw;
  378. console.log(files, "files文件");
  379. const key = file.name; // 设置上传到 COS 后的文件名
  380. cos.putObject(
  381. {
  382. Bucket: "wanzai-1306339220",
  383. Region: "ap-shanghai",
  384. Key: key,
  385. Body: files,
  386. onProgress: function (progressData) {
  387. console.log(JSON.stringify(progressData));
  388. },
  389. },
  390. function (err, data) {
  391. if (err) {
  392. console.error(err, "请求失败");
  393. } else {
  394. console.log(data, "请求成功");
  395. logoImg.value = "https://" + data.Location;
  396. // 成功
  397. }
  398. }
  399. );
  400. }
  401. }
  402. } else {
  403. ElMessage.error("图片格式必须为JPG/PNG格式!");
  404. }
  405. // ruleForm.coverImg = file.url;
  406. };
  407. // 选中时自动替换上一个文件。
  408. const handleExceed2 = (files) => {
  409. upload.value.clearFiles();
  410. const file = files[0];
  411. file.uid = genFileId();
  412. upload.value.handleStart(file);
  413. };
  414. onBeforeMount(async () => {
  415. api.value = store.state.user.api;
  416. getList();
  417. });
  418. </script>
  419. <style scoped lang="scss">
  420. .content-box {
  421. min-width: 1000px;
  422. width: calc(100vw - 260px);
  423. height: calc(100vh - 105px);
  424. margin: 20px auto;
  425. background-color: #fff;
  426. box-shadow: 0px 3px 10px rgba(0, 97, 255, 0.2);
  427. .header {
  428. display: flex;
  429. align-items: center;
  430. padding-left: 32px;
  431. height: 60px;
  432. font-size: 18px;
  433. font-weight: bold;
  434. border-bottom: 1px solid #cccccc;
  435. }
  436. .scroll {
  437. height: calc(100% - 61px);
  438. overflow: auto;
  439. :deep(.el-upload-list) {
  440. display: none;
  441. }
  442. }
  443. .title {
  444. display: flex;
  445. align-items: center;
  446. padding-left: 32px;
  447. height: 70px;
  448. font-size: 20px;
  449. font-weight: bold;
  450. .title_text {
  451. margin-right: 24px;
  452. }
  453. }
  454. .info {
  455. display: flex;
  456. align-items: center;
  457. padding-left: 86px;
  458. min-height: 40px;
  459. .info_img {
  460. display: flex;
  461. justify-content: center;
  462. align-items: center;
  463. margin: 10px 0 26px 0;
  464. width: 96px;
  465. height: 96px;
  466. border-radius: 50%;
  467. background-color: #e5e5e5;
  468. }
  469. .info_key {
  470. align-self: flex-start;
  471. margin-top: 10px;
  472. }
  473. .info_btn {
  474. margin-top: 10px;
  475. }
  476. }
  477. .info2 {
  478. flex-wrap: wrap;
  479. width: 215px;
  480. .icon_delete {
  481. align-self: flex-end;
  482. margin-bottom: 26px;
  483. margin-left: 10px;
  484. cursor: pointer;
  485. }
  486. }
  487. }
  488. </style>