charles
2024-05-20 0d91757d82f4cfd1586ab39cbe37f12d739ddc43
src/views/home/components/textManager/index.vue
@@ -10,11 +10,11 @@
                :destroy-on-close="true"
                >
            <el-form  ref="textForm" class="demo-form-inline" label-width="120px" :model="textObj" :rules="textRules">
                <el-form-item label="文字内容:" prop="textContent">
                    <el-input v-model="textObj.textContent" placeholder="请输入文字内容"/>
                <el-form-item label="文字内容:" prop="content">
                    <el-input v-model="textObj.content" placeholder="请输入文字内容"/>
                </el-form-item>
                <el-form-item label="车号:">
                    <el-input v-model="textObj.carNo" placeholder="请输入车号"/>
                    <el-input v-model="textObj.locomotiveNumber" placeholder="请输入车号"/>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
@@ -41,10 +41,14 @@
        </div>
        <div>
            <el-table :data="pageInfo.textList" >
                <el-table-column prop="id" label="序号" align="center" />
                <el-table-column prop="textContent" label="文字内容" align="center" />
                <el-table-column prop="cid" label="车号" align="center" />
                <el-table-column prop="date" label="添加时间" align="center"  />
                <el-table-column prop="ID" label="序号" align="center" />
                <el-table-column prop="content" label="文字内容" align="center" />
                <el-table-column prop="locomotiveNumber" label="车号" align="center" />
                <el-table-column prop="CreatedAt" label="添加时间" align="center" >
                    <template slot-scope="scope">
                        {{$moment(scope.row.CreatedAt).format('YYYY-MM-DD HH:mm:ss')}}
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <div class="total">共计{{pageInfo.total}}条记录 第{{pageData.page}}/{{lastPage}}页</div>
@@ -65,18 +69,19 @@
</template>
<script>
    import { getTextListApi,addTextApi} from '@/api';
    export default {
        name: "textManager",
        data(){
            return{
                textRules:{
                    textContent: [
                    content: [
                        { required: true, message: '内容不能为空', trigger: 'blur' },
                    ],
                },
                addModal:false,
                keyword:'',
                textObj:{textContent:'',carNo:''},
                textObj:{content:'',locomotiveNumber:''},
                pageInfo:{
                  total:100,
                  textList:[]
@@ -89,21 +94,22 @@
              return Math.ceil(this.pageInfo.total/this.pageData.pageSize)
          }
        },
        watch:{
          pageData:{
              handler(){
                  this.searchCar();
              },
              deep:true,
              immediate:true
          }
        },
        methods:{
            searchCar(){
                //搜索
                this.pageInfo.textList=[
                    {id:1, textContent: '火车启动', cid: 'k12', date: '2016-05-02'},
                    {id:2, textContent: '火车启动', cid: 'k12', date: '2016-05-02'},
                    {id:3, textContent: '火车启动', cid: 'k12', date: '2016-05-02'},
                    {id:4, textContent: '火车启动', cid: 'k12', date: '2016-05-02'},
                    {id:5, textContent: '火车启动', cid: 'k12', date: '2016-05-02'},
                    {id:6, textContent: '火车启动', cid: 'k12', date: '2016-05-02'},
                    {id:7, textContent: '火车启动', cid: 'k12', date: '2016-05-02'},
                    {id:8, textContent: '火车启动', cid: 'k12', date: '2016-05-02'},
                    {id:9, textContent: '火车启动', cid: 'k12', date: '2016-05-02'},
                    {id:10, textContent: '火车启动', cid: 'k12', date: '2016-05-02'}
                ];
            async searchCar(){
                const {code,data,total}=await getTextListApi({keyword:this.keyword,...this.pageData});
                if(code===200){
                    this.pageInfo.textList=data;
                    this.pageInfo.total=total;
                }
            },
            handleSizeChange(pageSize){
                this.pageData.pageSize=pageSize;
@@ -111,16 +117,25 @@
            handleCurrentChange(page){
                this.pageData.page=page;
            },
            resetFormData(){
              this.addModal=false;
              this.textObj={content:'',locomotiveNumber:''}
            },
            addText(){
                this.$refs.textForm.validate((valid) => {
                    if(valid){
                        addTextApi(this.textObj).then(({code})=>{
                            if(code===200){
                                this.$message.success('添加成功');
                                this.resetFormData();
                                this.searchCar();
                            }else{
                                this.$message.warning('添加失败')
                            }
                        });
                    }
                })
            }
        },
        mounted(){
            this.searchCar();
        }
    }
</script>