teacher.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. <template>
  2. <div
  3. class="pb_content"
  4. style="background: unset; height: 100%; overflow: auto"
  5. >
  6. <div
  7. class="pb_content_body"
  8. style="
  9. background: #fff;
  10. padding: 0px 25px;
  11. box-sizing: border-box;
  12. margin: 10px auto 0;
  13. /* border-radius: 5px; */
  14. "
  15. >
  16. <div class="pb_head">
  17. <span>教师管理</span>
  18. </div>
  19. <div class="student_head">
  20. <div class="head_left">
  21. <el-input
  22. v-model="sPhoneUser"
  23. class="student_input"
  24. placeholder="请输入用户名"
  25. ></el-input>
  26. <el-select
  27. v-model="cid"
  28. placeholder="请选择学校"
  29. class="student_input inputClass"
  30. @change="searchStudent"
  31. v-if="org && org != 'undefined' && org != 'null'"
  32. >
  33. <el-option label="所有学校" value=""></el-option>
  34. <el-option
  35. v-for="(item, index) in classJuri"
  36. :key="index"
  37. :label="item.name"
  38. :value="item.id"
  39. ></el-option>
  40. </el-select>
  41. <el-button class="student_button" @click="searchStudent"
  42. >查询</el-button
  43. >
  44. </div>
  45. <div class="head_right">
  46. <el-button @click="addStudent">添加教师</el-button>
  47. <el-upload
  48. class="upload-demo newCss"
  49. :http-request="handleChange"
  50. :on-remove="handleRemove"
  51. action="#"
  52. :file-list="fileListUpload"
  53. accept=".xlsx"
  54. >
  55. <el-button size="primary" type="primary">批量添加</el-button>
  56. <div slot="tip" class="el-upload__tip" style="margin-left: 10px">
  57. 只能上传xlsx文件,且不超过500kb
  58. </div>
  59. </el-upload>
  60. <!-- <el-button @click="exportExcel">导出学生</el-button> -->
  61. <div @click="getExcel">xls 上传样例</div>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="pb_content_body" style="margin: 0 auto">
  66. <div class="student_table">
  67. <el-table
  68. ref="table"
  69. :data="tableData"
  70. border
  71. :height="tableHeight"
  72. :fit="true"
  73. v-loading="isLoading"
  74. style="width: 100%"
  75. :header-cell-style="{ background: '#f1f1f1', fontSize: '17px' }"
  76. :row-class-name="tableRowClassName"
  77. >
  78. <el-table-column label="姓名" min-width="10" align="center">
  79. <template slot-scope="scope">
  80. <div class="userImg">
  81. <div class="tx">
  82. <img
  83. :src="
  84. scope.row.headportrait != null
  85. ? scope.row.headportrait
  86. : tx
  87. "
  88. alt
  89. />
  90. </div>
  91. <div
  92. style="
  93. width: 150px;
  94. text-align: left;
  95. white-space: nowrap;
  96. overflow: hidden;
  97. text-overflow: ellipsis;
  98. "
  99. >
  100. {{ scope.row.username }}
  101. </div>
  102. </div>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="教师账号" min-width="15" align="center">
  106. <template slot-scope="scope">
  107. <div>{{ scope.row.un ? scope.row.un : "" }}</div>
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="身份" min-width="15" align="center">
  111. <template slot-scope="scope">
  112. <div>{{ scope.row.role ? '管理员' : "普通教师" }}</div>
  113. </template>
  114. </el-table-column>
  115. <el-table-column
  116. prop="schoolName"
  117. label="学校"
  118. min-width="15"
  119. align="center"
  120. >
  121. </el-table-column>
  122. <el-table-column label="操作" width="220px">
  123. <template slot-scope="scope">
  124. <div style="display: flex;">
  125. <el-button
  126. size="mini"
  127. type="primary"
  128. @click="modifyDiaBtn(scope.row)"
  129. >修改</el-button
  130. >
  131. <div
  132. class="delete"
  133. @click="deleteStudent(scope.row.userid, scope.row.state)"
  134. >
  135. <img src="../../../assets/remove.png" alt />
  136. </div>
  137. </div>
  138. </template>
  139. </el-table-column>
  140. </el-table>
  141. </div>
  142. <div class="student_page">
  143. <el-pagination
  144. background
  145. layout="prev, pager, next"
  146. :page-size="10"
  147. :total="total"
  148. v-if="page"
  149. @current-change="handleCurrentChange"
  150. ></el-pagination>
  151. </div>
  152. </div>
  153. <el-dialog
  154. title="修改账号信息"
  155. :visible.sync="modifyDia"
  156. :append-to-body="true"
  157. width="700px"
  158. :before-close="handleClose"
  159. :close-on-click-modal="true"
  160. class="add_student"
  161. >
  162. <el-form class="inputClass">
  163. <el-form-item label="教师名称" :label-width="formLabelWidth">
  164. <span>
  165. <el-input
  166. placeholder="请输入教师姓名"
  167. clearable
  168. v-model.trim="modifyDiaData.dName"
  169. class="add_input"
  170. ></el-input>
  171. </span>
  172. </el-form-item>
  173. <el-form-item label="教师账号" :label-width="formLabelWidth">
  174. <span>
  175. <el-input
  176. placeholder="请输入教师姓名"
  177. clearable
  178. disabled
  179. v-model.trim="modifyDiaData.mail"
  180. class="add_input"
  181. ></el-input>
  182. </span>
  183. </el-form-item>
  184. <!-- <el-form-item label="手机号" :label-width="formLabelWidth">
  185. <span>
  186. <el-input
  187. placeholder="请输入手机号"
  188. clearable
  189. disabled
  190. v-model="modifyDiaData.tel"
  191. class="add_input"
  192. ></el-input>
  193. </span>
  194. </el-form-item> -->
  195. <el-form-item
  196. label="角色"
  197. :label-width="formLabelWidth"
  198. v-if="org && org != 'undefined' && org != 'null'"
  199. >
  200. <template>
  201. <el-radio v-model="modifyDiaData.radio" :label="0">管理员</el-radio>
  202. <el-radio v-model="modifyDiaData.radio" :label="1"
  203. >普通教师</el-radio
  204. >
  205. </template>
  206. </el-form-item>
  207. <!-- <el-form-item label="所属学校" :label-width="formLabelWidth" v-else>
  208. <el-select v-model="oidName.name" disabled>
  209. <el-option
  210. v-for="(item, index) in classJuri"
  211. :key="index"
  212. :label="item.name"
  213. :value="item.id"
  214. ></el-option>
  215. </el-select>
  216. </el-form-item> -->
  217. </el-form>
  218. <span slot="footer" class="dialog-footer flex">
  219. <el-button class="right" @click="conModify">确认</el-button>
  220. </span>
  221. </el-dialog>
  222. <el-dialog
  223. title="添加教师"
  224. :visible.sync="dialogVisible"
  225. :append-to-body="true"
  226. width="700px"
  227. :before-close="handleClose"
  228. :close-on-click-modal="true"
  229. class="add_student"
  230. >
  231. <!-- <div slot="title" class="header-title">
  232. <div class="logoImg">
  233. <img src="../../../assets/logo.png" alt />
  234. </div>
  235. <div class="title_add_student">添加教师</div>
  236. </div> -->
  237. <el-form class="inputClass">
  238. <el-form-item label="教师名称" :label-width="formLabelWidth">
  239. <span>
  240. <el-input
  241. placeholder="请输入教师姓名"
  242. clearable
  243. v-model="sName"
  244. class="add_input"
  245. ></el-input>
  246. </span>
  247. </el-form-item>
  248. <el-form-item label="教师账号" :label-width="formLabelWidth">
  249. <span>
  250. <el-input
  251. placeholder="请输入教师账号"
  252. clearable
  253. v-model="sMail"
  254. class="add_input"
  255. ></el-input>
  256. </span>
  257. </el-form-item>
  258. <el-form-item label="教师账号" :label-width="formLabelWidth">
  259. <span>
  260. <template>
  261. <el-radio v-model="addRadio" :label="0">管理员</el-radio>
  262. <el-radio v-model="addRadio" :label="1">普通教师</el-radio>
  263. </template>
  264. </span>
  265. </el-form-item>
  266. <el-form-item
  267. label="所属学校"
  268. :label-width="formLabelWidth"
  269. v-if="org && org != 'undefined' && org != 'null'"
  270. >
  271. <el-select v-model="schoolName" placeholder="请选择学校">
  272. <el-option
  273. v-for="(item, index) in classJuri"
  274. :key="index"
  275. :label="item.name"
  276. :value="item.id"
  277. ></el-option>
  278. </el-select>
  279. </el-form-item>
  280. <el-form-item label="所属学校" :label-width="formLabelWidth" v-else>
  281. <el-select v-model="oidName.name" disabled>
  282. <el-option
  283. v-for="(item, index) in classJuri"
  284. :key="index"
  285. :label="item.name"
  286. :value="item.id"
  287. ></el-option>
  288. </el-select>
  289. </el-form-item>
  290. <div style="text-align: center; color: #adb3b7">
  291. 注:添加教师的账号密码为123456
  292. </div>
  293. </el-form>
  294. <span slot="footer" class="dialog-footer flex">
  295. <el-button class="right" @click="insertStudent">确认</el-button>
  296. </span>
  297. </el-dialog>
  298. </div>
  299. </template>
  300. <script>
  301. import $ from "jquery";
  302. // import pinyin from "../../../../node_modules/js-pinyin/index";
  303. export default {
  304. data() {
  305. return {
  306. tableHeight: "500px",
  307. isLoading: false,
  308. formLabelWidth: "100px",
  309. tableData: [],
  310. dialogVisible: false,
  311. modifyDia: false,
  312. modifyDiaData: {
  313. userid: "",
  314. mail: "",
  315. dName: "",
  316. tel: "",
  317. radio: 0,
  318. type: 1,
  319. role: 0
  320. },
  321. sName: "",
  322. sMail: "",
  323. addPol: "",
  324. addTyp: 0,
  325. addRadio: 1,
  326. sId: "",
  327. schoolName: "",
  328. schoolJuri: [],
  329. classJuri: [],
  330. fileListUpload: [],
  331. oidName: [],
  332. page: 1,
  333. total: 0,
  334. sPhoneUser: "",
  335. userid: this.$route.query.userid,
  336. oid: this.$route.query.oid,
  337. cid: "",
  338. org: this.$route.query.org,
  339. tx: require("../../../assets/avatar.png"),
  340. userSuffix: ""
  341. };
  342. },
  343. mounted() {
  344. this.$nextTick(function() {
  345. this.getUser()
  346. this.tableHeight =
  347. window.innerHeight - this.$refs.table.$el.offsetTop - 200;
  348. if (this.tableHeight <= 530) {
  349. this.tableHeight = 530;
  350. }
  351. // 监听窗口大小变化
  352. let self = this;
  353. window.onresize = function() {
  354. self.tableHeight =
  355. window.innerHeight - self.$refs.table.$el.offsetTop - 200;
  356. if (self.tableHeight <= 530) {
  357. self.tableHeight = 530;
  358. }
  359. };
  360. });
  361. },
  362. methods: {
  363. getUser() {
  364. let params = {
  365. userid: this.userid
  366. };
  367. // console.log(111,params);
  368. this.ajax
  369. .get(this.$store.state.api + "selectUser", params)
  370. .then(res => {
  371. // console.log(res);
  372. this.userSuffix = res.data[0][0].accountNumber.split("@")[1];
  373. // console.log(this.userSuffix);
  374. })
  375. .catch(err => {
  376. console.error(err);
  377. });
  378. },
  379. // 确定修改信息
  380. conModify() {
  381. if (!this.modifyDiaData.dName) {
  382. this.$message({
  383. message: "教师名称不能为空",
  384. type: "error"
  385. });
  386. return;
  387. }
  388. let uRole = null;
  389. let uType = 1;
  390. if (!this.modifyDiaData.radio) {
  391. uRole = 1;
  392. } else {
  393. uRole = 0;
  394. }
  395. let params = [
  396. {
  397. uid: this.modifyDiaData.userid,
  398. uname: this.modifyDiaData.dName,
  399. rol: uRole,
  400. typ: uType
  401. }
  402. ];
  403. this.ajax
  404. .post(this.$store.state.api + "updateYTeacherInfo", params)
  405. .then(res => {
  406. this.$message({
  407. message: "修改成功",
  408. type: "success"
  409. });
  410. this.modifyDia = false;
  411. this.getStudent();
  412. })
  413. .catch(err => {
  414. this.isLoading = false;
  415. this.$message({
  416. message: "修改失败",
  417. type: "error"
  418. });
  419. console.error(err);
  420. });
  421. // return console.log(data);
  422. // this.
  423. },
  424. // 修改用户信息弹窗
  425. modifyDiaBtn(val) {
  426. // console.log(val);
  427. this.modifyDiaData.userid = val.userid;
  428. this.modifyDiaData.dName = val.username;
  429. this.modifyDiaData.tel = "";
  430. this.modifyDiaData.role = val.role;
  431. this.modifyDiaData.type = val.type;
  432. this.modifyDiaData.mail = val.un;
  433. if (val.role == 1) {
  434. this.modifyDiaData.radio = 0;
  435. } else {
  436. this.modifyDiaData.radio = 1;
  437. }
  438. this.modifyDia = true;
  439. },
  440. tableRowClassName({ row, rowIndex }) {
  441. if ((rowIndex + 1) % 2 === 0) {
  442. return "even_row";
  443. } else {
  444. return "";
  445. }
  446. },
  447. searchStudent() {
  448. this.page = 1;
  449. this.getStudent();
  450. },
  451. addStudent() {
  452. this.dialogVisible = true;
  453. (this.sName = ""), (this.sMail = ""), (this.schoolName = "");
  454. if (this.org && this.org != "undefined" && this.org != "null") {
  455. this.getClass();
  456. } else {
  457. this.getOidName();
  458. }
  459. // this.getSchool();
  460. },
  461. handleClose(done) {
  462. done();
  463. },
  464. getExcel(res) {
  465. require.ensure([], () => {
  466. const {
  467. export_json_to_excel
  468. } = require("../../../common/Export2Excel");
  469. const tHeader = ["教师姓名", "教师账号", "学校"];
  470. const data = [];
  471. export_json_to_excel(tHeader, data, "上传教师样例");
  472. });
  473. },
  474. handleCurrentChange(val) {
  475. this.page = val;
  476. this.getStudent();
  477. },
  478. time() {
  479. if (!this.now) {
  480. this.now = new Date().getTime();
  481. return true;
  482. } else {
  483. let time = new Date().getTime();
  484. if (time - this.now > 3000) {
  485. this.now = time;
  486. return true;
  487. } else {
  488. return false;
  489. }
  490. }
  491. },
  492. //新增学生
  493. insertStudent() {
  494. this.dialogVisible = true;
  495. if (this.org && this.org != "undefined" && this.org != "null") {
  496. if (this.sName === "") {
  497. this.$message.error("教师姓名不能为空");
  498. return;
  499. } else if (this.sMail === "") {
  500. this.$message.error("教师账号不能为空");
  501. return;
  502. } else if (this.schoolName === "") {
  503. this.$message.error("请选择学校");
  504. return;
  505. }
  506. // else if (
  507. // // !/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/.test(
  508. // // this.sMail
  509. // // )
  510. // this.sMail === ""
  511. // ) {
  512. // this.$message.error("学生账号不能为空");
  513. // // this.$message.error("邮箱格式不正确");
  514. // return;
  515. // }
  516. } else {
  517. if (this.sName === "") {
  518. this.$message.error("教师姓名不能为空");
  519. return;
  520. } else if (this.sMail === "") {
  521. this.$message.error("教师账号不能为空");
  522. return;
  523. }
  524. // else if (
  525. // // !/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/.test(
  526. // // this.sMail
  527. // // )
  528. // this.sMail === ""
  529. // ) {
  530. // this.$message.error("学生账号不能为空");
  531. // // this.$message.error("邮箱格式不正确");
  532. // return;
  533. // }
  534. }
  535. let mail = '';
  536. if(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/.test(this.sMail)){
  537. mail = this.sMail;
  538. }else{
  539. mail = this.sMail + "@" + this.userSuffix
  540. }
  541. if (this.time()) {
  542. // let params = { un: this.sMail };
  543. let params = { un: mail};
  544. // console.log('mail',mail,this.userSuffix);
  545. this.ajax
  546. .get(this.$store.state.api + "findMail", params)
  547. .then(res => {
  548. if (res.data[0].length > 0) {
  549. this.$message.error("此邮箱已被注册");
  550. } else {
  551. this.add_Student();
  552. }
  553. })
  554. .catch(err => {
  555. console.error(err);
  556. });
  557. }
  558. },
  559. add_Student() {
  560. let AddT = 1;
  561. let addR = 0;
  562. if (!this.addRadio) {
  563. addR = 1;
  564. } else {
  565. addR = 0;
  566. }
  567. let mail = '';
  568. if(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/.test(this.sMail)){
  569. mail = this.sMail;
  570. }else{
  571. mail = this.sMail + "@" + this.userSuffix
  572. }
  573. let params = [
  574. {
  575. username: mail,
  576. userpassword: 123456,
  577. alias: this.sName,
  578. org:
  579. this.org && this.org != "undefined" && this.org != "null"
  580. ? this.org
  581. : "",
  582. oid:
  583. this.org && this.org != "undefined" && this.org != "null"
  584. ? this.schoolName
  585. : this.oid,
  586. ph: this.sPhone,
  587. sid: this.sId,
  588. cid: "",
  589. typ: AddT,
  590. rol: addR
  591. }
  592. ];
  593. // return console.log('params:',params);
  594. this.ajax
  595. .post(this.$store.state.api + "teacherRegistration", params)
  596. .then(res => {
  597. // debugger;
  598. // let params = [
  599. // {
  600. // userid: res.data.uid,
  601. // username: this.sName,
  602. // sid: this.sId,
  603. // type: 1,
  604. // org: this.org,
  605. // oid: res.data.oid,
  606. // phone: res.data.ph,
  607. // cid: "",
  608. // intro: "",
  609. // sex: "0"
  610. // }
  611. // ];
  612. // this.ajax
  613. // .post(this.$store.state.api + "updateUserByEdu1", params)
  614. // .then(res => {
  615. // console.log(res);
  616. // })
  617. // .catch(err => {
  618. // console.error(err);
  619. // });
  620. this.$message({
  621. message: "新增成功",
  622. type: "success"
  623. });
  624. this.dialogVisible = false;
  625. this.sName = "";
  626. this.sMail = "";
  627. this.schoolName = "";
  628. this.getStudent();
  629. })
  630. .catch(err => {
  631. this.isLoading = false;
  632. this.$message({
  633. message: "新增失败",
  634. type: "error"
  635. });
  636. console.error(err);
  637. });
  638. },
  639. //获取班级列表
  640. getClass() {
  641. this.isLoading = true;
  642. let params = {
  643. org: this.org
  644. };
  645. this.ajax
  646. .get(this.$store.state.api + "selectSchoolByOrg", params)
  647. .then(res => {
  648. this.isLoading = false;
  649. this.classJuri = res.data[0];
  650. })
  651. .catch(err => {
  652. this.isLoading = false;
  653. console.error(err);
  654. });
  655. },
  656. //获取学校名称
  657. getOidName() {
  658. this.isLoading = true;
  659. let params = {
  660. oid: this.oid
  661. };
  662. this.ajax
  663. .get(this.$store.state.api + "selectSchoolName2", params)
  664. .then(res => {
  665. this.isLoading = false;
  666. this.oidName = res.data[0][0];
  667. })
  668. .catch(err => {
  669. this.isLoading = false;
  670. console.error(err);
  671. });
  672. },
  673. // getSchool() {
  674. // this.isLoading = true;
  675. // let params = {
  676. // page: this.page,
  677. // };
  678. // this.ajax
  679. // .get(this.$store.state.api + "selectOrg", params)
  680. // .then((res) => {
  681. // this.isLoading = false;
  682. // this.schoolJuri = res.data[0];
  683. // })
  684. // .catch((err) => {
  685. // this.isLoading = false;
  686. // console.error(err);
  687. // });
  688. // },
  689. getStudent() {
  690. this.isLoading = true;
  691. let params = {
  692. org:
  693. this.org && this.org != "undefined" && this.org != "null"
  694. ? this.org
  695. : "",
  696. oid:
  697. this.org && this.org != "undefined" && this.org != "null"
  698. ? ""
  699. : this.oid,
  700. cu: this.cid,
  701. cn: this.sPhoneUser,
  702. page: this.page
  703. };
  704. this.ajax
  705. .get(this.$store.state.api + "selectOrgTeachar", params)
  706. .then(res => {
  707. this.isLoading = false;
  708. this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
  709. this.tableData = res.data[0];
  710. // console.log("this.tableData", this.tableData);
  711. })
  712. .catch(err => {
  713. this.isLoading = false;
  714. console.error(err);
  715. });
  716. },
  717. handleChange(file) {
  718. this.fileTemp = file.file;
  719. if (this.fileTemp) {
  720. if (
  721. this.fileTemp.type ==
  722. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ||
  723. this.fileTemp.type == "application/vnd.ms-excel"
  724. ) {
  725. this.importCount = 1;
  726. this.importfxx(this.fileTemp);
  727. } else {
  728. this.$message({
  729. type: "warning",
  730. message: "附件格式错误,请删除后重新上传!"
  731. });
  732. }
  733. } else {
  734. this.$message({
  735. type: "warning",
  736. message: "请上传附件!"
  737. });
  738. }
  739. },
  740. handleRemove(file, fileList) {
  741. this.fileTemp = null;
  742. },
  743. exportExcel() {
  744. try {
  745. let params = {
  746. oid: this.oid
  747. };
  748. this.ajax
  749. .get(this.$store.state.api + "selectUserBySchool", params)
  750. .then(res => {
  751. var res = res.data[0];
  752. //如果value的json字段的key值和想要的headers值不一致时,可做如下更改
  753. //将和下面的Object.fromEntries结合,将json字段的key值改变为要求的excel的header值
  754. var array = [];
  755. for (var i = 0; i < res.length; i++) {
  756. var _json = {};
  757. _json["用户名"] = res[i].username;
  758. _json["姓名"] = res[i].alias ? res[i].alias : "";
  759. _json["班级"] = res[i].classid ? res[i].classid : "";
  760. array.push(_json);
  761. }
  762. var XLSX = require("xlsx");
  763. const workbook = XLSX.utils.book_new(); //创建一个新的工作簿对象
  764. let ws = XLSX.utils.json_to_sheet(array); //将json对象数组转化成工作表
  765. ws["!cols"] = [
  766. //设置每一列的宽度
  767. { wch: 50 },
  768. { wch: 50 },
  769. { wch: 50 }
  770. ];
  771. XLSX.utils.book_append_sheet(workbook, ws, "sheet1"); //把sheet添加到workbook里,第三个参数是sheet名
  772. XLSX.writeFile(workbook, "学生信息.xlsx");
  773. // const wopts = { bookType: "xlsx", bookSST: false, type: "array" };//写入的样式bookType:输出的文件类型,type:输出的数据类型,bookSST: 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性
  774. // const wbout = XLSX.write(workbook, wopts);// 浏览器端和node共有的API,实际上node可以直接使用xlsx.writeFile来写入文件,但是浏览器没有该API
  775. // FileSaver.saveAs(new Blob([wbout], { type: "application/octet-stream" }), `${title} demo.xlsx`);//保存文件
  776. this.$message({
  777. message: "导出成功",
  778. type: "success"
  779. });
  780. })
  781. .catch(err => {
  782. console.error(err);
  783. });
  784. } catch (e) {
  785. console.log(e, e.stack);
  786. }
  787. },
  788. importfxx(obj) {
  789. const loading = this.$loading.service({
  790. background: "rgba(255, 255, 255, 0.7)",
  791. target: document.body
  792. });
  793. var _$ = $;
  794. this.importCount++;
  795. let _this = this;
  796. // 通过DOM取文件数据
  797. this.file = obj;
  798. var rABS = false; //是否将文件读取为二进制字符串
  799. var f = this.file;
  800. var reader = new FileReader();
  801. //if (!FileReader.prototype.readAsBinaryString) {
  802. FileReader.prototype.readAsBinaryString = function(f) {
  803. var binary = "";
  804. var rABS = false; //是否将文件读取为二进制字符串
  805. var pt = this;
  806. var wb; //读取完成的数据
  807. var outdata;
  808. var reader = new FileReader();
  809. reader.onload = function(e) {
  810. var bytes = new Uint8Array(reader.result);
  811. var length = bytes.byteLength;
  812. for (var i = 0; i < length; i++) {
  813. binary += String.fromCharCode(bytes[i]);
  814. }
  815. var XLSX = require("xlsx");
  816. if (rABS) {
  817. wb = XLSX.read(btoa(fixdata(binary)), {
  818. //手动转化
  819. type: "base64"
  820. });
  821. } else {
  822. wb = XLSX.read(binary, {
  823. type: "binary"
  824. });
  825. }
  826. outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); //outdata就是你想要的东西
  827. this.da = [...outdata];
  828. let arr = [];
  829. this.da.map(v => {
  830. let obj = {};
  831. obj.name = v["教师姓名"];
  832. obj.mail = v["教师账号"];
  833. obj.school = v["学校"];
  834. arr.push(obj);
  835. });
  836. console.log(arr);
  837. let _b = 1;
  838. for (var i = 0; i < arr.length; i++) {
  839. let item = arr[i];
  840. if (item.school === "") {
  841. _b = 1;
  842. _this.$message.error("教师学校不能为空,请重新上传");
  843. break;
  844. } else if (item.name === "") {
  845. _b = 1;
  846. _this.$message.error("教师姓名不能为空,请重新上传");
  847. break;
  848. } else if (item.mail === "") {
  849. _b = 1;
  850. _this.$message.error("教师账号不能为空,请重新上传");
  851. } else if (
  852. !/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/.test(
  853. item.mail
  854. )
  855. ) {
  856. _b = 1;
  857. _this.$message.error("有教师账号格式不正确,请重新上传");
  858. break;
  859. }
  860. }
  861. let z = 2;
  862. let newArr = JSON.stringify(arr);
  863. let params = [
  864. {
  865. arr: newArr,
  866. userpassword: 123456,
  867. org:
  868. _this.org && _this.org != "undefined" && _this.org != "null"
  869. ? _this.org
  870. : ""
  871. }
  872. ];
  873. _this.ajax
  874. .post(_this.$store.state.api + "batchRegistrationMore1", params)
  875. .then(res => {
  876. if (z == 2) {
  877. _this.$message({
  878. message: "新增成功",
  879. type: "success"
  880. });
  881. _this.getStudent();
  882. }
  883. loading.close();
  884. })
  885. .catch(err => {
  886. console.error(err);
  887. });
  888. _this.fileListUpload = [];
  889. };
  890. reader.readAsArrayBuffer(f);
  891. };
  892. if (rABS) {
  893. reader.readAsArrayBuffer(f);
  894. } else {
  895. reader.readAsBinaryString(f);
  896. }
  897. },
  898. getSchoolName() {
  899. let params = {
  900. oid: this.oid
  901. };
  902. this.ajax
  903. .get(this.$store.state.api + "selectSchoolName2", params)
  904. .then(res => {
  905. this.schoolName = res.data[0][0].name;
  906. })
  907. .catch(err => {
  908. console.error(err);
  909. });
  910. },
  911. deleteStudent(id, state) {
  912. state = 0;
  913. let params = [{ uid: id, state: state }];
  914. this.$confirm("确定" + "删除" + "此教师吗?", "提示", {
  915. confirmButtonText: "确定",
  916. cancelButtonText: "取消",
  917. type: "warning"
  918. })
  919. .then(() => {
  920. this.ajax
  921. .post(this.$store.state.api + "deleteStudent", params)
  922. .then(res => {
  923. this.$message({
  924. message: "操作成功",
  925. type: "success"
  926. });
  927. this.getStudent();
  928. })
  929. .catch(err => {
  930. this.$message.error("操作失败");
  931. console.error(err);
  932. });
  933. })
  934. .catch(() => {});
  935. }
  936. },
  937. created() {
  938. this.page = 1;
  939. this.getStudent();
  940. this.getSchoolName();
  941. this.getClass();
  942. }
  943. };
  944. </script>
  945. <style scoped>
  946. @media screen and (max-width: 1024px) {
  947. .student_head {
  948. flex-direction: column !important;
  949. }
  950. .head_right {
  951. margin-top: 10px !important;
  952. }
  953. }
  954. .pb_head > span:nth-child(2) {
  955. font-size: 20px;
  956. margin-left: 5px;
  957. color: #828282;
  958. }
  959. .pb_head {
  960. margin: 0 !important;
  961. width: 100% !important;
  962. }
  963. .student_page {
  964. margin-top: 10px;
  965. }
  966. .student_head {
  967. margin-top: 10px;
  968. padding-bottom: 10px;
  969. display: flex;
  970. justify-content: space-between;
  971. }
  972. .head_left {
  973. display: flex;
  974. align-items: center;
  975. }
  976. .head_right {
  977. display: flex;
  978. flex-direction: row;
  979. flex-wrap: nowrap;
  980. align-items: baseline;
  981. }
  982. .student_input >>> .el-input__inner {
  983. height: 30px;
  984. width: 190px;
  985. font-size: 13px;
  986. padding: 0 10px;
  987. }
  988. .student_button {
  989. color: #fff;
  990. background: #2268bc;
  991. width: 60px;
  992. height: 30px;
  993. padding: 0 !important;
  994. font-size: 12px;
  995. line-height: 30px;
  996. }
  997. .head_right > button:nth-child(1) {
  998. color: #fff;
  999. background: #2268bc;
  1000. width: 70px;
  1001. height: 30px;
  1002. padding: 0 !important;
  1003. font-size: 12px;
  1004. line-height: 30px;
  1005. }
  1006. .head_right > button:nth-child(2) {
  1007. color: #fff;
  1008. background: #2268bc;
  1009. width: 70px;
  1010. height: 30px;
  1011. padding: 0 !important;
  1012. font-size: 12px;
  1013. line-height: 30px;
  1014. }
  1015. .head_right > div {
  1016. font-size: 12px;
  1017. line-height: 40px;
  1018. margin-left: 10px;
  1019. color: #2a6dbe;
  1020. text-decoration: underline;
  1021. cursor: pointer;
  1022. }
  1023. .student_table >>> .el-table--border td {
  1024. border-right: 0px !important;
  1025. }
  1026. .student_table >>> .el-table,
  1027. .student_table >>> .el-table__body-wrapper {
  1028. height: auto !important;
  1029. }
  1030. .el-table >>> .even_row {
  1031. background-color: #f1f1f1 !important;
  1032. }
  1033. .de_button {
  1034. color: #fff;
  1035. background: #5190fd;
  1036. width: 50px;
  1037. height: 25px;
  1038. padding: 0 !important;
  1039. font-size: 12px;
  1040. line-height: 25px;
  1041. }
  1042. .add_student >>> .el-dialog__header {
  1043. padding: 20px 20px 10px;
  1044. text-align: center;
  1045. background: #454545;
  1046. }
  1047. .add_student >>> .el-dialog__title {
  1048. font-size: 14px !important;
  1049. color: #fff !important;
  1050. }
  1051. .add_student >>> .el-dialog__headerbtn {
  1052. font-size: 20px !important;
  1053. }
  1054. .add_student >>> .el-form-item__label {
  1055. margin-left: 65px;
  1056. }
  1057. .add_student >>> .el-form-item {
  1058. display: flex;
  1059. }
  1060. .add_student >>> .el-form-item__content {
  1061. margin: 0 !important;
  1062. }
  1063. .add_input {
  1064. width: 365px;
  1065. }
  1066. .add_student >>> .el-dialog__footer {
  1067. text-align: center !important;
  1068. }
  1069. .right {
  1070. width: 250px;
  1071. color: #fff;
  1072. background: #2268bc;
  1073. margin-bottom: 20px;
  1074. }
  1075. .header-title {
  1076. display: flex;
  1077. }
  1078. .logoImg {
  1079. width: 30px;
  1080. }
  1081. .logoImg > img {
  1082. width: 100%;
  1083. height: 100%;
  1084. }
  1085. .title_add_student {
  1086. margin: 0 auto;
  1087. color: #fff;
  1088. }
  1089. .upload-demo {
  1090. line-height: 0px !important;
  1091. }
  1092. .upload-demo >>> .el-button {
  1093. color: #fff;
  1094. background: #2268bc;
  1095. width: 70px;
  1096. height: 30px;
  1097. padding: 0 !important;
  1098. font-size: 12px;
  1099. line-height: 0 !important;
  1100. }
  1101. .userImg {
  1102. display: flex;
  1103. flex-direction: row;
  1104. justify-content: center;
  1105. align-items: center;
  1106. }
  1107. .tx {
  1108. width: 40px;
  1109. margin-right: 10px;
  1110. }
  1111. .delete {
  1112. width: 25px;
  1113. height: 25px;
  1114. cursor: pointer;
  1115. margin-left: 10px;
  1116. }
  1117. .tx > img,
  1118. .delete > img {
  1119. width: 100%;
  1120. height: 100%;
  1121. }
  1122. .newCss {
  1123. display: flex;
  1124. flex-direction: row;
  1125. flex-wrap: nowrap;
  1126. align-items: baseline;
  1127. }
  1128. .student_input.el-input {
  1129. width: auto;
  1130. }
  1131. .student_input {
  1132. margin-right: 10px;
  1133. }
  1134. .student_input >>> .el-input__icon {
  1135. line-height: unset;
  1136. }
  1137. </style>