vue項(xiàng)目記錄鎖定和解鎖功能實(shí)現(xiàn)
更新時(shí)間:2022年03月07日 12:04:43 作者:chengqiuming
這篇文章主要為大家詳細(xì)介紹了vue項(xiàng)目記錄鎖定和解鎖功能實(shí)現(xiàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了vue項(xiàng)目記錄鎖定和解鎖功能實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
一、定義 api 模塊
import request from '@/utils/request' ? export default { ? ? // 分頁查詢 ? ? getHospitalList(current, limit, searchObj) { ? ? ? ? return request({ ? ? ? ? ? ? url: `/admin/hospital/findPageHospital/${current}/${limit}`, ? ? ? ? ? ? method: 'post', ? ? ? ? ? ? data: searchObj // 使用 json 進(jìn)行參數(shù)傳遞 ? ? ? ? }) ? ? }, ? ? // 單條刪除醫(yī)院 ? ? deleteHospital(id) { ? ? ? ? return request({ ? ? ? ? ? ? url: `/admin/hospital/${id}`, ? ? ? ? ? ? method: 'delete' ? ? ? ? }) ? ? }, ? ? // 批量刪除醫(yī)院 ? ? removeHospitals(idList) { ? ? ? ? return request({ ? ? ? ? ? ? url: `/admin/hospital/batchRemove`, ? ? ? ? ? ? method: 'delete', ? ? ? ? ? ? data: idList ? ? ? ? }) ? ? }, ? ? //鎖定和取消鎖定 ? ? lockHospital(id, status) { ? ? ? ? return request({ ? ? ? ? ? ? url: `/admin/hospital/lockHospital/${id}/${status}`, ? ? ? ? ? ? method: 'put' ? ? ? ? }) ? ? } }
二、頁面部分
<template> ? <div class="app-container"> ? ? <!-- 條件查詢 --> ? ? <el-form :inline="true" class="demo-form-inline"> ? ? ? <el-form-item> ? ? ? ? <el-input v-model="searchObj.name" placeholder="醫(yī)院名稱" /> ? ? ? </el-form-item> ? ? ? <el-form-item> ? ? ? ? <el-input v-model="searchObj.province" placeholder="省" /> ? ? ? </el-form-item> ? ? ? <el-form-item> ? ? ? ? <el-input v-model="searchObj.city" placeholder="市" /> ? ? ? </el-form-item> ? ? ? <el-form-item> ? ? ? ? <el-input v-model="searchObj.district" placeholder="區(qū)" /> ? ? ? </el-form-item> ? ? ? <el-button type="primary" icon="el-icon-search" @click="getList()">搜索</el-button> ? ? </el-form> ? ? <!-- 批量刪除按鈕 --> ? ? <div> ? ? ? <el-button type="danger" size="mini" @click="removeRows()">批量刪除</el-button> ? ? </div> ? ? <!-- 列表 --> ? ? <el-table :data="list" stripe style="width: 100%" @selection-change="handleSelectionChange"> ? ? ? <!-- 復(fù)選框 --> ? ? ? <el-table-column type="selection" width="55" /> ? ? ? <el-table-column type="index" width="50" /> ? ? ? <el-table-column prop="name" label="名稱" /> ? ? ? <el-table-column prop="province" label="省" /> ? ? ? <el-table-column prop="city" label="市" /> ? ? ? <el-table-column prop="district" label="區(qū)" /> ? ? ? <el-table-column label="狀態(tài)" width="80"> ? ? ? ? <template slot-scope="scope">{{ scope.row.status === 1 ? '可用' : '不可用' }}</template> ? ? ? </el-table-column> ? ? ? <el-table-column label="操作" width="280" align="center"> ? ? ? ? <template slot-scope="scope"> ? ? ? ? ? <!-- 刪除按鈕 --> ? ? ? ? ? <el-button ? ? ? ? ? ? type="danger" ? ? ? ? ? ? size="mini" ? ? ? ? ? ? icon="el-icon-delete" ? ? ? ? ? ? @click="removeDataById(scope.row.id)" ? ? ? ? ? >刪除</el-button> ? ? ? ? ? <!-- 鎖定按鈕 --> ? ? ? ? ? <el-button ? ? ? ? ? ? v-if="scope.row.status==1" ? ? ? ? ? ? type="primary" ? ? ? ? ? ? size="mini" ? ? ? ? ? ? icon="el-icon-delete" ? ? ? ? ? ? @click="lockHospital(scope.row.id,0)" ? ? ? ? ? >鎖定</el-button> ? ? ? ? ? <!-- 解鎖按鈕 --> ? ? ? ? ? <el-button ? ? ? ? ? ? v-if="scope.row.status==0" ? ? ? ? ? ? type="danger" ? ? ? ? ? ? size="mini" ? ? ? ? ? ? icon="el-icon-delete" ? ? ? ? ? ? @click="lockHospital(scope.row.id,1)" ? ? ? ? ? >解鎖</el-button> ? ? ? ? </template> ? ? ? </el-table-column> ? ? </el-table> ? ? <!-- 分頁 --> ? ? <el-pagination ? ? ? :current-page="page" ? ? ? :page-size="limit" ? ? ? :total="total" ? ? ? style="padding: 30px 0; text-align: center;" ? ? ? layout="total, prev, pager, next, jumper" ? ? ? @current-change="getList" ? ? /> ? </div> </template> </div> </template> ? <script> // 引入接口定義的 js 文件 import hospital from "@/api/hospital"; ? export default { ? // 定義變量和初始值 ? data() { ? ? return { ? ? ? current: 1, // 當(dāng)前頁 ? ? ? limit: 3, // 每頁顯示記錄數(shù) ? ? ? searchObj: {}, // 條件封裝對象 ? ? ? list: [], // 沒頁數(shù)據(jù)集合 ? ? ? total: 0, // 總記錄數(shù) ? ? ? multipleSelection: [] // 批量選擇中選擇的記錄列表 ? ? }; ? }, ? // 在頁面渲染之前執(zhí)行,一般調(diào)用 methods 中定義的方法,得到數(shù)據(jù) ? created() { ? ? this.getList(); ? }, ? methods: { ? ? // 定義方法,進(jìn)行請求接口調(diào)用 ? ? // 鎖定和解鎖 ? ? lockHospital(id, status) { ? ? ? hospital.lockHospital(id, status).then(response => { ? ? ? ? // 刷新 ? ? ? ? this.getList(); ? ? ? }); ? ? }, ? ? ? // 當(dāng)表格復(fù)選框選項(xiàng)發(fā)生變化的時(shí)候觸發(fā) ? ? handleSelectionChange(selection) { ? ? ? this.multipleSelection = selection; ? ? }, ? ? // 批量刪除醫(yī)院 ? ? removeRows() { ? ? ? this.$confirm("此操作將永久刪除醫(yī)院信息, 是否繼續(xù)?", "提示", { ? ? ? ? confirmButtonText: "確定", ? ? ? ? cancelButtonText: "取消", ? ? ? ? type: "warning" ? ? ? }).then(() => { ? ? ? ? // 確定執(zhí)行 then 方法 ? ? ? ? var idList = []; ? ? ? ? // 遍歷數(shù)組得到每個(gè) id 值,設(shè)置到 idList 里面 ? ? ? ? for (var i = 0; i < this.multipleSelection.length; i++) { ? ? ? ? ? var obj = this.multipleSelection[i]; ? ? ? ? ? var id = obj.id; ? ? ? ? ? idList.push(id); ? ? ? ? } ? ? ? ? // 調(diào)用接口 ? ? ? ? hospital.removeHospitals(idList).then(response => { ? ? ? ? ? // 提示 ? ? ? ? ? this.$message({ ? ? ? ? ? ? type: "success", ? ? ? ? ? ? message: "刪除成功!" ? ? ? ? ? }); ? ? ? ? ? // 刷新頁面 ? ? ? ? ? this.getList(); ? ? ? ? }); ? ? ? }); ? ? }, ? ? ? // 醫(yī)院列表 ? ? getList(page = 1) { ? ? ? // 添加當(dāng)前頁參數(shù) ? ? ? this.current = page; ? ? ? hospital ? ? ? ? .getHospitalList(this.current, this.limit, this.searchObj) ? ? ? ? .then(response => { ? ? ? ? ? // response 是接口返回?cái)?shù)據(jù) ? ? ? ? ? this.list = response.data.records; ? ? ? ? ? this.total = response.data.total; ? ? ? ? }) // 請求成功 ? ? ? ? .catch(error => {}); ? ? }, // 請求失敗 ? ? ? // 單條刪除醫(yī)院 ? ? removeDataById(id) { ? ? ? this.$confirm("此操作將永久刪除醫(yī)院信息, 是否繼續(xù)?", "提示", { ? ? ? ? confirmButtonText: "確定", ? ? ? ? cancelButtonText: "取消", ? ? ? ? type: "warning" ? ? ? }).then(() => { ? ? ? ? // 確定執(zhí)行 then 方法 ? ? ? ? // 調(diào)用接口 ? ? ? ? hospital.deleteHospital(id).then(response => { ? ? ? ? ? // 提示 ? ? ? ? ? this.$message({ ? ? ? ? ? ? type: "success", ? ? ? ? ? ? message: "刪除成功!" ? ? ? ? ? }); ? ? ? ? ? // 刷新頁面 ? ? ? ? ? this.getList(1); ? ? ? ? }); ? ? ? }); ? ? } ? } }; </script>
三、測試效果
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
elementui中tabel組件的scope.$index的使用及說明
這篇文章主要介紹了elementui中tabel組件的scope.$index的使用及說明,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10Vue如何實(shí)現(xiàn)變量表達(dá)式選擇器
這篇文章主要介紹了Vue如何實(shí)現(xiàn)變量表達(dá)式選擇器,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下2021-02-02詳解vuex中的this.$store.dispatch方法
這篇文章主要介紹了vuex中的this.$store.dispatch方法,必須要用commit(‘SET_TOKEN’,?tokenV)調(diào)用mutations里的方法,才能在store存儲成功,需要的朋友可以參考下2022-11-11vue+elementUI組件遞歸實(shí)現(xiàn)可折疊動態(tài)渲染多級側(cè)邊欄導(dǎo)航
這篇文章主要介紹了vue+elementUI組件遞歸實(shí)現(xiàn)可折疊動態(tài)渲染多級側(cè)邊欄導(dǎo)航,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04vue中div禁止點(diǎn)擊事件的實(shí)現(xiàn)
這篇文章主要介紹了vue中div禁止點(diǎn)擊事件的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04