teachName.vue 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. <template>
  2. <div class="page_search" ref="page_content">
  3. <div class="search_content">
  4. <div class="content_left">
  5. <el-button class="tab_button" @click="ChangeActiveTab('enableUse')" :class="statusPage=='enableUse'?'select_cur':''">启用用户</el-button>
  6. <el-button class="tab_button" @click="ChangeActiveTab('disabledUse')" :class="statusPage=='disabledUse'?'select_cur':''">禁用用户</el-button>
  7. <el-button class="tab_button" @click="ChangeActiveTab('lsuser')" :class="statusPage=='lsuser'?'select_cur':''">临时用户</el-button>
  8. </div>
  9. </div>
  10. <div class="page_jg"></div>
  11. <div class="search_content">
  12. <div class="content_left">
  13. <el-input style="width: 230px;" v-model="keyWord" @input="SearchTeacher" placeholder="教师姓名、账号">
  14. <el-button slot="append" icon="el-icon-search" @click="SearchTeacher"></el-button>
  15. </el-input>
  16. </div>
  17. <div class="content_right">
  18. <!-- <el-button @click="ResetPassWord('AllUser')">重置密码</el-button> -->
  19. <el-button @click="BathDisabled" v-if="statusPage=='disabledUse'||statusPage=='enableUse'">{{ statusPage=='disabledUse'?'批量启用':'批量禁用' }}</el-button>
  20. <input type="file" ref="uploadStudents" @change="ImportTeacherList" enctype="multipart/form-data" style="display:none;"/>
  21. <el-button @click="BatchExport">批量导出</el-button>
  22. <el-tooltip class="item" effect="dark" content="当前导入的为教师用户的基本信息" placement="top">
  23. <el-button @click="BatchImport" v-if="statusPage=='enableUse'">批量导入</el-button>
  24. </el-tooltip>
  25. <!-- <el-button @click="uploadImage" v-if="statusPage=='enableUse'">上传头像</el-button> -->
  26. <input type="file" ref="fileImage" accept="image/*" multiple @change="handleFiles" style="display:none"/>
  27. <!-- <el-button class="dowmTepl" @click="DownloadTemplent()">下载模板</el-button> -->
  28. <el-button type="primary" plain @click="AddTeach()" v-if="statusPage=='enableUse'">新增教师</el-button>
  29. </div>
  30. </div>
  31. <div class="page_jg_16"></div>
  32. <div class="page_table">
  33. <el-table ref="teacherTable" :data="teacherList" border stripe @selection-change="HandleSelectionChange" :height="tableHeight">
  34. <el-table-column type="selection" width="55" align="center"></el-table-column>
  35. <el-table-column type="index" label="序号" :index="GetIndexNumber" width="80" align="center"></el-table-column>
  36. <el-table-column prop="headPic" label="头像" align="center">
  37. <template slot-scope="scope">
  38. <img :src="scope.row.headPic" alt="" class="picStyle" v-if="scope.row.headPic">
  39. <div v-else>-</div>
  40. </template>
  41. </el-table-column>
  42. <el-table-column prop="userAccount" label="账号" align="center">
  43. <template slot-scope="scope">
  44. <span>{{ scope.row.userAccount }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="teacherName" label="姓名" align="center">
  48. <template slot-scope="scope">
  49. <div>{{ !scope.row.teacherName?'-':scope.row.teacherName }}</div>
  50. </template>
  51. </el-table-column>
  52. <el-table-column prop="gender" label="性别" align="center">
  53. <template slot-scope="scope">
  54. <div>
  55. {{ scope.row.gender == 1 ? '女' :scope.row.gender ==0? '男':'-'}}
  56. </div>
  57. </template>
  58. </el-table-column>
  59. <el-table-column prop="email" label="邮箱" align="center" show-overflow-tooltip :cell-class-name="'ellipsis-tooltip'">
  60. <template slot-scope="scope">
  61. <span>{{ scope.row.email || '-' }}</span>
  62. </template>
  63. </el-table-column>
  64. <el-table-column prop="userType" label="类型" align="center">
  65. <template slot-scope="scope">
  66. <!-- 用户类型0-正式,1-临时用户 -->
  67. {{scope.row.userType==0 ? '正式' : '临时'}}
  68. </template>
  69. </el-table-column>
  70. <el-table-column prop="status" label="状态" align="center">
  71. <template slot-scope="scope">
  72. <div class="table_row_status">
  73. <div :class="scope.row.status==1?'normal_icon':'abnormal_icon'"></div>&nbsp;{{ scope.row.status == 1 ? '启用' : '禁用'}}
  74. </div>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="操作" align="center" width="360px">
  78. <template slot-scope="scope">
  79. <div class="table_row_option">
  80. <!-- <div class="button_delete" @click="UpdateEmail(scope.row)">{{!scope.row.email?'绑定邮箱':'解绑邮箱'}}</div> -->
  81. <div class="button_editor" @click="AddTeach('edit', scope.row)">编辑</div>
  82. <div class="button_editor" @click="ResetPassWord(scope.row)">重置密码</div>
  83. <div class="button_editor" @click="DisabledTeach(scope.row)">{{!scope.row.status?'启用':'禁用'}}</div>
  84. <div class="button_delete" @click="DeleteTeach(scope.row)">删除</div>
  85. </div>
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. </div>
  90. <div class="page_pagination" style=" margin-bottom: 10px;">
  91. <el-pagination
  92. @current-change="ChangePage"
  93. background
  94. layout="sizes,prev, pager, next"
  95. @size-change="HandleSizeChange"
  96. :page-sizes="[20,50,100]"
  97. :current-page="pageInfo.pageNum"
  98. :total="pageInfo.total">
  99. </el-pagination>
  100. </div>
  101. <div class="page_dialog">
  102. <!-- 新增教师-->
  103. <el-dialog :title="editTeachData.title" center :visible.sync="editTeachData.dialogShow" width="480px">
  104. <div class="dialog_center padding_20">
  105. <el-form :model="editTeachData" :rules="editTeachDataRules" ref="editTeachData" label-width="110px">
  106. <el-form-item label="账号:" prop="userAccount">
  107. <el-input v-model="editTeachData.userAccount" ></el-input>
  108. </el-form-item>
  109. <el-form-item label="姓名:" prop="teacherName">
  110. <el-input v-model="editTeachData.teacherName"></el-input>
  111. </el-form-item>
  112. <el-form-item label="性别:" prop="gender">
  113. <el-select v-model="editTeachData.gender" placeholder="请选择" style="width:100%;">
  114. <el-option
  115. v-for="item in genderOptions"
  116. :key="item.value"
  117. :label="item.label"
  118. :value="item.value">
  119. </el-option>
  120. </el-select>
  121. </el-form-item>
  122. </el-form>
  123. </div>
  124. <div slot="footer" class="dialog-footer">
  125. <el-button @click="editTeachData.dialogShow = false">取 消</el-button>
  126. <el-button type="primary" @click="ConfirmTeacherAdd">确 定</el-button>
  127. </div>
  128. </el-dialog>
  129. <!-- 重置密码 -->
  130. <el-dialog title="重置密码" center :visible.sync="editPassWordData.dialogShow" width="480px">
  131. <div class="dialog_center padding_20">
  132. <el-form :model="editPassWordData" ref="editPassWordData" label-width="110px" >
  133. <el-form-item label="教师姓名:" prop="teacherName" >
  134. <el-input :value="editPassWordData.teacherName" disabled/>
  135. </el-form-item>
  136. <el-form-item label="重置方式:">
  137. <el-radio-group v-model="editPassWordData.useDefault">
  138. <el-radio label="0">使用新密码</el-radio>
  139. <el-radio label="1">重置为默认密码</el-radio>
  140. </el-radio-group>
  141. </el-form-item>
  142. <el-form-item label="新密码:" v-if="editPassWordData.useDefault=='0'">
  143. <el-input v-model="editPassWordData.randomPassword" />
  144. </el-form-item>
  145. <el-form-item label="默认密码:" v-if="editPassWordData.useDefault=='1'">
  146. <div class="default_pass">
  147. <el-input value="******" disabled/>
  148. <p>默认密码:学校编号@教师账号</p>
  149. </div>
  150. </el-form-item>
  151. </el-form>
  152. </div>
  153. <div slot="footer" class="dialog-footer">
  154. <el-button size="small" @click="editPassWordData.dialogShow = false">取 消</el-button>
  155. <el-button size="small" type="primary" @click="ConfirmPassWord" :loading="loading">确 定</el-button>
  156. </div>
  157. </el-dialog>
  158. <!-- 批量禁用 -->
  159. <el-dialog title="批量禁用" center width="450px" :visible.sync="batchDisabledData.dialogShow">
  160. <el-form :model="batchDisabledData" label-width="80px">
  161. <el-form-item label="禁用:" prop="isOverGrade">
  162. <el-radio-group v-model="radioDisabled">
  163. <el-radio :label="0">禁用</el-radio>
  164. <el-radio :label="1">启用</el-radio>
  165. </el-radio-group>
  166. </el-form-item>
  167. </el-form>
  168. <div slot="footer" class="dialog-footer">
  169. <el-button size="small" @click="batchDisabledData.dialogShow = false">取 消</el-button>
  170. <el-button size="small" type="primary" @click="confirmBatchDisabled">确 定</el-button>
  171. </div>
  172. </el-dialog>
  173. </div>
  174. </div>
  175. </template>
  176. <script>
  177. import { throttle } from "lodash";
  178. import { encrypt } from "@/utils/jsencrypt";
  179. export default{
  180. name:"teachtName",
  181. data(){
  182. return {
  183. selTermList:{
  184. value:"",
  185. name:"",
  186. schoolGradeId:"",
  187. arr:[]
  188. },
  189. queryData:{
  190. "semesterId":"",
  191. "classType":"", //0-行政班 1-教学班
  192. "courseId":"",
  193. "queryStr":"",
  194. "schoolClassId":""
  195. },
  196. teacherList:[],//教师列表
  197. pageInfo:{
  198. total:0,
  199. pageSize:20,
  200. pageNum:1,
  201. },//页面初始数据
  202. keyWord:'',//搜索输入框数据
  203. editTeachData:{
  204. "dialogShow":false,
  205. "title":"新增教师",//弹窗标题
  206. "isEdit":false,//是否编辑
  207. "gender": 0,//性别,2-未知,0-男,1-女
  208. "email": "",//邮箱
  209. "id":"",//id
  210. "teacherCode":"",//教师ID(教工号) 暂未使用
  211. "teacherName":"",//教师姓名
  212. "userAccount":"",//用户账号
  213. "teacherId":"",//教师id
  214. },
  215. editTeachDataRules: {
  216. userAccount: [
  217. { required: true, message: '请输入账号', trigger: 'blur' },
  218. { min: 6, max: 30, message: '账号名称6-30个字符', trigger: 'blur' }
  219. ],
  220. teacherName: [
  221. { required: true, message: '请输入姓名', trigger: 'blur' },
  222. ],
  223. gender: [
  224. { required: false, message: '', trigger: 'blur' },
  225. ],
  226. },
  227. batchDisabledData:{
  228. dialogShow:false,
  229. },
  230. genderOptions:[{
  231. value: 2,
  232. label: '-'
  233. },{
  234. value: 0,
  235. label: '男'
  236. },{
  237. value: 1,
  238. label: '女'
  239. }],
  240. isEdit:"",
  241. useStyle:{
  242. background:"#2E64FA",
  243. color:"#fff",
  244. border:'1px solid #2E64FA',
  245. },
  246. disabledStyle:{
  247. background:"#fff",
  248. color:"#666666",
  249. border: "1px solid #DCDFE6"
  250. },
  251. lsyhStyle:{
  252. background:"#fff",
  253. color:"#666666",
  254. border: "1px solid #DCDFE6"
  255. },
  256. statusPage:"enableUse",//默认启用账号
  257. editPassWordData:{
  258. dialogShow:false,
  259. useDefault:'1',//重置方式0 新密码 1 默认密码
  260. id:"",//用户id
  261. teacherName:"",//用户姓名
  262. randomPassword:""//新密码
  263. },//教师重置密码
  264. editPassWordDataRules:{
  265. randomPassword:[
  266. { required: true, message: '请输入新密码', trigger: 'blur' },
  267. { min: 6, message: '密码长度不能少于6位', trigger: 'blur' }
  268. ],
  269. },
  270. checkPass:false,
  271. setPass:"",
  272. radioDisabled:0,
  273. files: [],
  274. multipleSelection:[],
  275. loading: false,
  276. mainHeight:0,
  277. tableHeight:0,//table高度
  278. }
  279. },
  280. mounted(){
  281. this.GetTeacherList();//获取教师列表
  282. this.SetTableHeight(); //设置表格高度
  283. window.addEventListener("resize", this.HandleResize); //监听窗口大小变化
  284. },
  285. beforeDestroy() {
  286. // 组件销毁移除监听 防止内存泄漏
  287. window.removeEventListener("resize", this.HandleResize);
  288. },
  289. methods:{
  290. //获取序号
  291. GetIndexNumber(index)
  292. {
  293. let indexCount=(this.pageInfo.pageNum - 1) * this.pageInfo.pageSize + index +1 ;
  294. return indexCount
  295. },
  296. // 监听窗口大小变化,重新计算表格高度 使用节流防止频繁改变窗口大小导致计算量过大而页面卡顿
  297. HandleResize: throttle(function () {
  298. this.SetTableHeight();
  299. }, 500), // 节流 500 毫秒内最多执行一次
  300. //设置表格高度
  301. SetTableHeight()
  302. {
  303. let windowViewHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  304. this.$nextTick(() => {
  305. this.tableHeight = windowViewHeight - 365;
  306. });
  307. },
  308. //获取教师列表
  309. GetTeacherList()
  310. {
  311. let param = {
  312. userType:0,
  313. accountName:this.keyWord,//用户名称
  314. pageNum:this.pageInfo.pageNum,
  315. pageSize:this.pageInfo.pageSize,
  316. status:1,//正式用户必传 0=禁用 1=启用
  317. };
  318. //
  319. if(this.statusPage=='enableUse')
  320. {
  321. //启用账户
  322. param.userType=0;//临时账号 用户类型0-正式,1-临时用户
  323. param.status=1;//启用
  324. }
  325. if(this.statusPage=='disabledUse')
  326. {
  327. //禁用账号
  328. param.userType=0;//临时账号 用户类型0-正式,1-临时用户
  329. param.status=0;//启用
  330. }
  331. if(this.statusPage=='lsuser')
  332. {
  333. //临时账号
  334. param.userType=1;//临时账号 用户类型0-正式,1-临时用户
  335. param.status=1;
  336. }
  337. this.$api.user.getTeacherList(param).then(res=>{
  338. if(res.code == 200)
  339. {
  340. this.teacherList = res.data.records || [];
  341. this.pageInfo.total = parseInt(res.data.total);
  342. }
  343. })
  344. },
  345. //重置分页数据
  346. ResetPageData()
  347. {
  348. this.pageInfo={
  349. total:0,
  350. pageSize:20,
  351. pageNum:1,
  352. };
  353. },
  354. //切换tab
  355. ChangeActiveTab(item)
  356. {
  357. this.statusPage = item;
  358. this.ResetPageData();
  359. this.GetTeacherList();//获取教师列表
  360. },
  361. //搜索教师
  362. SearchTeacher(){
  363. this.ResetPageData();
  364. this.GetTeacherList();//获取教师列表
  365. },
  366. //页面改变
  367. ChangePage(e){
  368. this.pageInfo.pageNum = e;
  369. this.GetTeacherList();//获取教师列表
  370. this.TableScrollTop();
  371. },
  372. //页面分页切换改变
  373. HandleSizeChange(val)
  374. {
  375. this.pageInfo.pageSize = val;
  376. this.GetTeacherList();//获取教师列表
  377. this.TableScrollTop();
  378. },
  379. //重置表格滚动条
  380. TableScrollTop()
  381. {
  382. this.$nextTick(() => {
  383. if (this.$refs.teacherTable) {
  384. const tableBody = this.$refs.teacherTable.$el.querySelector('.el-table__body-wrapper');
  385. if (tableBody) {
  386. tableBody.scrollTop = 0;
  387. }
  388. }
  389. });
  390. },
  391. //编辑新增教师确定
  392. ConfirmTeacherAdd()
  393. {
  394. this.$refs["editTeachData"].validate((valid) => {
  395. if (valid)
  396. {
  397. let param={
  398. "gender": this.editTeachData.gender,
  399. "teacherCode": this.editTeachData.teacherCode,
  400. "teacherId": this.editTeachData.teacherId,
  401. "teacherName": this.editTeachData.teacherName,
  402. "userAccount": this.editTeachData.userAccount
  403. };
  404. if(this.editTeachData.isEdit)
  405. {
  406. param.id=this.editTeachData.id;
  407. }
  408. this.$api.user.addAndUpdateTeacher(param).then((res)=>{
  409. if(res.code == 200)
  410. {
  411. this.$message.success("保存成功!")
  412. this.editTeachData.dialogShow = false;
  413. this.GetTeacherList();
  414. }
  415. else
  416. {
  417. this.$message.error("保存失败!"+res.msg)
  418. }
  419. })
  420. }
  421. })
  422. },
  423. //重置密码
  424. ResetPassWord(item)
  425. {
  426. this.editPassWordData={
  427. dialogShow:true,
  428. useDefault:'1',//重置方式0 新密码 1 默认密码
  429. id:item.id,//用户id
  430. teacherName:item.teacherName,//用户姓名
  431. randomPassword:''//新密码
  432. };
  433. },
  434. //重置密码
  435. ConfirmPassWord()
  436. {
  437. if(this.editPassWordData.useDefault=='1')
  438. {
  439. //默认密码
  440. let param={
  441. ids: [this.editPassWordData.id],//用户id
  442. useDefault: 1//重置方式 使用默认密码 0-否 1-是
  443. };
  444. this.loading=true;
  445. this.$api.user.resetPassWord(param).then(res=>{
  446. this.loading=false;
  447. if(res.code==200)
  448. {
  449. this.$message({
  450. type: 'success',
  451. message:"重置成功!"
  452. });
  453. this.editPassWordData.dialogShow = false;
  454. }
  455. })
  456. }
  457. else
  458. {
  459. //新密码
  460. if(this.editPassWordData.randomPassword)
  461. {
  462. }
  463. else
  464. {
  465. this.$message({
  466. message: '请输入新密码',
  467. type: 'warning'
  468. });
  469. return
  470. }
  471. let param={
  472. ids: [this.editPassWordData.id],//用户id
  473. password: encrypt(this.editPassWordData.randomPassword.trim()),//新密码
  474. useDefault: 0//重置方式 使用默认密码 0-否 1-是
  475. };
  476. this.loading=true;
  477. this.$api.user.resetPassWord(param).then(res=>{
  478. this.loading=false;
  479. if(res.code==200)
  480. {
  481. this.$message({
  482. type: 'success',
  483. message:"重置成功!"
  484. });
  485. this.editPassWordData.dialogShow = false;
  486. }
  487. })
  488. }
  489. },
  490. //表格选择事件
  491. HandleSelectionChange(val)
  492. {
  493. this.multipleSelection = val;
  494. },
  495. //批量禁用 或者启用
  496. BathDisabled()
  497. {
  498. if(this.multipleSelection.length===0)
  499. {
  500. this.$message({
  501. message: '请至少选择一个用户!',
  502. type: 'warning'
  503. });
  504. return;
  505. }
  506. let ids=[];
  507. let status=1;//启用
  508. this.multipleSelection.map(item=>ids.push(item.id));
  509. if(this.statusPage=='disabledUse')
  510. {
  511. status=1;//启用
  512. }
  513. else
  514. {
  515. status=0;//禁用
  516. }
  517. let param = {
  518. ids:ids,
  519. status:status,//状态 1-启用 0-禁用
  520. };
  521. this.$api.user.updateUserEnable(param).then((res)=>{
  522. if(res.code == 200)
  523. {
  524. this.$message({
  525. type: 'success',
  526. message: '操作成功!'
  527. });
  528. this.GetTeacherList();
  529. }
  530. })
  531. },
  532. //批量禁用确定
  533. confirmBatchDisabled() {
  534. if (this.multipleSelection.length === 0) {
  535. let warningMessage = this.statusPage == 'disabledUse'
  536. ? '未选择启用的数据'
  537. : '未选择禁用的数据';
  538. this.$message.warning(warningMessage);
  539. return; // 提前返回,避免嵌套
  540. }
  541. let param = { ids:[] };
  542. this.multipleSelection.map(a=>param.ids.push(a.id))
  543. this.$api.school.updateStatusEnable(param)
  544. .then((res) => {
  545. if (res.code === 200) {
  546. this.$message({
  547. type: 'success',
  548. message: res.msg
  549. });
  550. // this.batchDisabledData.dialogShow = false;
  551. this.loading=false;
  552. this.resetPageData();
  553. this.teacherList=[];
  554. this.listTeacherUser(this.statusPage);
  555. }
  556. })
  557. .catch((error) => {
  558. // 处理错误
  559. this.$message.error('操作失败,请重试');
  560. console.error(error);
  561. });
  562. },
  563. // 批量导入教师列表
  564. ImportTeacherList(){
  565. let formdata = new FormData();
  566. formdata.append("file",this.$refs.uploadStudents.files[0]);
  567. this.$api.user.importTeacherList(formdata).then((res)=>{
  568. if(res.code == 200){
  569. //刷新
  570. this.$message.success("导入成功");
  571. this.GetTeacherList();//获取教师列表
  572. }
  573. else
  574. {
  575. // this.$message.error("导入失败");
  576. this.$confirm("导入失败! "+res.msg, '提示', {
  577. confirmButtonText: '确定',
  578. showCancelButton: false,
  579. closeOnClickModal:false,
  580. customClass: "page_dialog",
  581. type: 'error'
  582. }).then(() => {
  583. }).catch(() => { });
  584. }
  585. this.$refs.uploadStudents.value = '';
  586. })
  587. },
  588. //批量导入教师事件
  589. BatchImport(){
  590. this.$refs.uploadStudents.value = null;
  591. this.$refs.uploadStudents.click();
  592. },
  593. //批量导出
  594. BatchExport()
  595. {
  596. let param = {
  597. userType:0,//用户类型0-正式,1-临时用户
  598. accountName:this.keyWord,//用户名称
  599. status:1,//正式用户必传 0=禁用 1=启用
  600. }
  601. if(this.statusPage=='enableUse')
  602. {
  603. //启用账户
  604. param.userType=0;//临时账号 用户类型0-正式,1-临时用户
  605. param.status=1;//启用
  606. }
  607. if(this.statusPage=='disabledUse')
  608. {
  609. //禁用账号
  610. param.userType=0;//临时账号 用户类型0-正式,1-临时用户
  611. param.status=0;//禁用
  612. }
  613. if(this.statusPage=='lsuser')
  614. {
  615. //临时账号
  616. param.userType=1;//临时账号 用户类型0-正式,1-临时用户
  617. param.status=1;
  618. }
  619. this.$api.user.exportTeacherList(param).then((res)=>{
  620. const blob = new Blob([res.data], {
  621. type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  622. });
  623. const a = document.createElement("a");
  624. a.href = URL.createObjectURL(blob);
  625. a.download = decodeURIComponent(res.headers["content-disposition"].split("filename=")[1]);
  626. a.click();
  627. URL.revokeObjectURL(a.href);
  628. a.remove();
  629. })
  630. },
  631. //下载模板
  632. DownloadTemplent()
  633. {
  634. //下载教师模板
  635. this.$api.user.exportTeacherTemplate().then((res)=>{
  636. const blob = new Blob([res.data], {
  637. type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  638. });
  639. const a = document.createElement("a");
  640. a.href = URL.createObjectURL(blob);
  641. a.download = decodeURIComponent(res.headers["content-disposition"].split("filename=")[1]);
  642. a.click();
  643. URL.revokeObjectURL(a.href);
  644. a.remove();
  645. })
  646. },
  647. //新增教师
  648. AddTeach(isEdit,item)
  649. {
  650. this.isEdit = isEdit;
  651. if(this.isEdit=='edit')
  652. {
  653. this.editTeachData={
  654. "dialogShow":true,
  655. "title":"编辑教师",//弹窗标题
  656. "isEdit":true,//是否编辑
  657. "gender": item.gender,//性别,2-未知,0-男,1-女
  658. "email": item.email,//邮箱
  659. "id":item.id,//id
  660. "teacherCode":item.teacherCode,//教师ID(教工号) 暂未使用
  661. "teacherName":item.teacherName,//教师姓名
  662. "userAccount":item.userAccount,//用户账号
  663. "teacherId":item.teacherId,//教师id
  664. };
  665. }
  666. else
  667. {
  668. this.editTeachData={
  669. "dialogShow":true,
  670. "title":"新增教师",//弹窗标题
  671. "isEdit":false,//是否编辑
  672. "gender": 2,//性别,2-未知,0-男,1-女
  673. "email": "",//邮箱
  674. "id":"",//id
  675. "teacherCode":"",//教师ID(教工号) 暂未使用
  676. "teacherName":"",//教师姓名
  677. "userAccount":"",//用户账号
  678. "teacherId":"",//教师id
  679. };
  680. }
  681. },
  682. //删除
  683. DeleteTeach(item)
  684. {
  685. this.$confirm(`确定要删除 ${item.teacherName}(${item.userAccount})吗?`, '提示', {
  686. confirmButtonText: '确定',
  687. cancelButtonText: '取消',
  688. type: 'warning',
  689. customClass:'page_dialog',
  690. }).then(() => {
  691. let param = {
  692. id:item.id//用户id
  693. }
  694. this.$api.user.deleteUserTeacher(param).then((res)=>{
  695. if(res.code == 200){
  696. this.$message({
  697. type: 'success',
  698. message: '删除成功!'
  699. });
  700. if(this.teacherList.length==1)
  701. {
  702. // 如果是当前页最后一个 删除后跳转到上一页
  703. if(this.pageInfo.pageNum>1)
  704. {
  705. this.pageInfo.pageNum--;
  706. }
  707. }
  708. this.GetTeacherList();
  709. }
  710. }).catch()
  711. }).catch(() => {
  712. //取消
  713. });
  714. },
  715. //禁用
  716. DisabledTeach(item)
  717. {
  718. // 状态(正式用户0=禁用 1=启用 临时用户代表0-关闭 1-开启)
  719. if(this.statusPage=='disabledUse'){
  720. this.$confirm(`确认要启用用户 ${item.teacherName}(${item.userAccount}) 吗?`, '提示', {
  721. confirmButtonText: '确定',
  722. cancelButtonText: '取消',
  723. type: 'warning',
  724. customClass:'page_dialog',
  725. }).then(() => {
  726. let param = {
  727. ids:[item.id],
  728. status:1,//状态 1-启用 0-禁用
  729. };
  730. this.$api.user.updateUserEnable(param).then((res)=>{
  731. if(res.code == 200){
  732. this.$message({
  733. type: 'success',
  734. message: '启用成功!'
  735. });
  736. this.GetTeacherList();
  737. }
  738. }).catch()
  739. }).catch(() => {
  740. //取消
  741. });
  742. }else{
  743. this.$confirm(`确认要禁用用户${item.teacherName}(${item.userAccount}) 吗?`, '提示', {
  744. confirmButtonText: '确定',
  745. cancelButtonText: '取消',
  746. type: 'warning',
  747. customClass:'page_dialog',
  748. }).then(() => {
  749. let param = {
  750. ids:[item.id],
  751. status:0,//状态 1-启用 0-禁用
  752. };
  753. this.$api.user.updateUserEnable(param).then((res)=>{
  754. if(res.code == 200){
  755. this.$message({
  756. type: 'success',
  757. message: '禁用成功!'
  758. });
  759. this.GetTeacherList();
  760. }
  761. }).catch()
  762. }).catch(() => {
  763. //取消
  764. });
  765. }
  766. },
  767. //解绑和绑定邮箱
  768. UpdateEmail(item){
  769. if(!item.email){
  770. this.$prompt('请输入邮箱', '提示', {
  771. confirmButtonText: '确定',
  772. cancelButtonText: '取消',
  773. inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
  774. inputErrorMessage: '邮箱格式不正确'
  775. }).then(({ value }) => {
  776. let param={
  777. "email": value,
  778. "userId": item.id
  779. }
  780. this.$api.school.batchBindUserEmail([param]).then((res)=>{
  781. if(res.code == 200){
  782. if(res.data.length>0){
  783. this.$message.warning("该邮箱已被其他用户绑定过!")
  784. }else{
  785. this.$message.success("绑定成功!")
  786. }
  787. this.loading=false;
  788. this.resetPageData();
  789. this.teacherList=[];
  790. this.listTeacherUser(this.statusPage);
  791. }
  792. }).catch((err)=>{})
  793. }).catch(() => {
  794. this.$message({
  795. type: 'info',
  796. message: '取消输入'
  797. });
  798. });
  799. }else{
  800. this.$confirm(`确认要解绑教师${item.username}的邮箱绑定信息吗?`, '提示', {
  801. confirmButtonText: '确定',
  802. cancelButtonText: '取消',
  803. type: 'warning',
  804. customClass:'page_dialog',
  805. }).then(() => {
  806. let param = {ids:[item.id]}
  807. this.$api.school.batchUnBindUserEmail(param).then((res)=>{
  808. if(res.code == 200){
  809. this.$message.success("解绑成功!")
  810. this.loading=false;
  811. this.resetPageData();
  812. this.teacherList=[];
  813. this.listTeacherUser(this.statusPage);
  814. }
  815. }).catch((err)=>{})
  816. }).catch(() => {
  817. //取消
  818. });
  819. }
  820. },
  821. uploadImage(){
  822. if(this.teacherList.length>0){
  823. this.$refs.fileImage.click();
  824. }else{
  825. this.$message.warning('当前无教师信息');
  826. }
  827. },
  828. handleFiles(event) {
  829. this.files = Array.from(event.target.files);
  830. this.uploadFiles();
  831. },
  832. async uploadFiles() {
  833. const base64Images = await Promise.all(this.files.map(file => this.convertToBase64(file)));
  834. const payload = {
  835. base64Images: base64Images.map(({ fileName, imgData }) => ({
  836. fileName,
  837. imgData,
  838. urlSuffix: 'teacher/', // 根据需要设置 URL 后缀
  839. })),
  840. semesterId: this.selTermList.value,
  841. type: 1,
  842. };
  843. service1.post(base.prefix +'/api/v1/teach/oss/file/uploadFiles', payload)
  844. .then(response => {
  845. this.$message.success(response.data.msg);
  846. this.loading=false;
  847. this.resetPageData();
  848. this.teacherList=[];
  849. this.listTeacherUser(this.statusPage);
  850. // 处理成功逻辑
  851. })
  852. .catch(error => {
  853. console.error('上传失败:', error);
  854. // 处理失败逻辑
  855. });
  856. },
  857. convertToBase64(file) {
  858. return new Promise((resolve, reject) => {
  859. const reader = new FileReader();
  860. reader.onload = () => {
  861. resolve({
  862. fileName: file.name,
  863. imgData:`data:image/jpeg;base64,${reader.result.split(',')[1]}` // 获取 base64 编码部分
  864. });
  865. };
  866. reader.onerror = reject;
  867. reader.readAsDataURL(file);
  868. });
  869. },
  870. },
  871. }
  872. </script>
  873. <style lang="scss" scoped>
  874. </style>