• 商品大类C


    export function getServerUrl(){
        return "http://localhost:80/";
    }
    
    
    • 1
    • 2
    • 3
    • 4
    <template>
      <el-dialog
        :model-value="dialogVisible"
        :title="dialogTitle"
        width="30%"
        @close="handleClose"
      >
        <el-form ref="formRef" :model="form" label-width="100px" :rules="rules">
          <el-form-item label="大类名称" prop="name">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="大类描述" prop="remark">
            <el-input
              v-model="form.remark"
              :rows="4"
              type="textarea"
            />
          </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="handleClose">取消</el-button>
            <el-button type="primary" @click="handleConfirm"
            >确认</el-button
            >
          </span>
        </template>
      </el-dialog>
    </template>
    
    <script setup>
    import { defineEmits,ref ,defineProps,watch} from 'vue'
    import axios from "@/util/axios";
    import { ElMessage } from "element-plus";
    
    const props=defineProps({
      dialogTitle:{
        type:String,
        default:'',
        required:true
      },
      id:{
        type:Number,
        default:-1,
        required:true
      }
    })
    
    const initFormData=async(id)=>{
      const res=await axios.get("admin/bigType/"+id);
      form.value=res.data.bigType;
    }
    
    const form=ref({
      id:-1,
      name:'',
      remark:''
    })
    
    watch(
      ()=>props.id,
      ()=>{
        console.log("id="+props.id);
        let id=props.id
    
        form.value.id=id;
    
        if(id!=-1){
          // 请求后端 获取数据
          initFormData(id)
        }
      },
      {deep:true,immediate:true}
    )
    
    
    const emits=defineEmits(['update:modelValue','initBigTypeList'])
    
    const formRef=ref(null)
    
    const handleClose = () => {
      emits('update:modelValue',false)
      formRef.value.resetFields();
    }
    
    
    const rules=ref({
      name:[
        {
          required: true,
          message: '请输入商品大类名称!',
        }
      ],
      remark:[
        {
          required: true,
          message: '请输入商品大类描述!',
        },
      ]
    })
    
    const handleConfirm = () => {
      formRef.value.validate(async (valid) => {
        if (valid) {
          try{
    
            let result=await axios.post("admin/bigType/save",form.value);
            let data=result.data;
            if(data.code==0){
              ElMessage.success("执行成功");
              formRef.value.resetFields();
              emits("initBigTypeList")
              handleClose();
            }else{
              ElMessage.error(data.msg);
            }
          }catch(err){
            console.log("error:"+err)
            ElMessage.error('系统运行出错,请联系管理员');
          }
        } else {
          return false
        }
      })
    }
    </script>
    
    <style scoped>
    
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    <template>
    
      <el-dialog
        :model-value="imageDialogVisible"
        title="商品大类图片更换"
        width="30%"
        @close="handleClose"
        center
      >
    
        <el-form ref="formRef" :model="form" label-width="100px" style="text-align: center">
    
    
    <!--        <el-upload
              class="avatar-uploader"
              :action="getServerUrl()+'/admin/bigType/uploadImage'"
              show-file-list=false
              accept="image/png,image/gif,image/jpg,image/jpeg"
              auto-upload=false
              list-type="picture-card"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar" />
              <el-icon v-else class="avatar-uploader-icon"><plus /></el-icon>
            </el-upload>-->
    <!--       <el-image
              style="width: 200px; height: 200px"
              :src="imageSrc"
              fit="fit"
            >
    
           </el-image>-->
    <!--       <el-upload
              :action="getServerUrl()+'/admin/bigType/uploadImage'"
              :data="actionData"
              show-file-list=false
              >
            <el-button type="primary">点击上传图片</el-button>
            </el-upload>-->
    
          <el-upload
            :headers="headers"
            class="avatar-uploader"
            :action="getServerUrl()+'/admin/bigType/uploadImage'"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          > <img v-if="imageUrl" :src="imageUrl" class="avatar" />
            <el-icon v-else class="avatar-uploader-icon"><plus /></el-icon>
          </el-upload>
    
    
        </el-form>
    
        <template #footer>
    
          <span class="dialog-footer">
    
            <el-button type="primary" @click="handleConfirm"
            >确认更换</el-button
            >
          </span>
    
        </template>
    
      </el-dialog>
    
    </template>
    
    <script setup>
    import { defineEmits,ref ,defineProps,watch} from 'vue'
    import axios from "@/util/axios";
    import { ElMessage  } from "element-plus";
    import {getServerUrl} from "@/config/sys";
    import { Plus } from '@element-plus/icons-vue'
    
    const emits=defineEmits(['update:modelValue','initBigTypeList'])
    
    
    
    const props=defineProps({
      imageDialogValue:{
        type:Object,
        default:()=>{}
      }
    })
    
    const form=ref({
      id:-1,
      image:''
    })
    
    const imageUrl=ref("")
    
    const headers=ref({
      token:window.sessionStorage.getItem('token')
    })
    
    const actionData=ref({id:form.value.id})
    
    const imageSrc=ref("")
    
    
    
    watch(
      ()=>props.imageDialogValue,
      ()=>{
        console.log("imageDialogValue=="+props.imageDialogValue);
        form.value=props.imageDialogValue;
        actionData.value.id= form.value.id;
        imageSrc.value=getServerUrl()+'/image/bigType/'+form.value.image;
        // form.value.id=id;
        console.log(form.value)
    
      },
      {deep:true,immediate:true}
    )
    
    const beforeAvatarUpload = (file) => {
      const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2
    
      if (!isJPG) {
        ElMessage.error('图片必须是jpg格式')
      }
      if (!isLt2M) {
        ElMessage.error('图片大小不能超过2M!')
      }
      return isJPG && isLt2M
    }
    
    const handleAvatarSuccess = (res) => {
     console.log(res.data)
      imageUrl.value=getServerUrl()+res.data.src;
      form.value.image=res.data.title;
    }
    
    
    const handleConfirm = async() => {
      let result=await axios.post("admin/bigType/save",form.value);
      let data=result.data;
      if(data.code==0){
        ElMessage.success("执行成功");
        imageUrl.value=""
       emits("initBigTypeList")
       handleClose();
      }else{
        ElMessage.error(data.msg);
      }
    }
    
    const handleClose = () => {
      emits('update:modelValue',false)
    }
    
    </script>
    
    <style >
    
    .avatar-uploader .el-upload {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
      border-color: #409eff;
    }
    .el-icon.avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      text-align: center;
    }
    .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }
    
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    <template>
      <el-card>
        <el-row :gutter="20" class="header">
          <el-col :span="7">
            <el-input placeholder="请输入商品大类名称..." clearable v-model="queryForm.query"></el-input>
          </el-col>
          <el-button type="primary" :icon="Search" @click="initBigTypeList">搜索</el-button>
          <el-button type="primary" @click="handleDialogValue()">添加商品大类</el-button>
        </el-row>
        <el-table :data="tableData" stripe style="width: 100%">
          <el-table-column prop="id" label="#ID" width="80" />
    
          <el-table-column prop="name" label="商品大类名称" width="200" />
    
          <el-table-column  prop="image" label="商品大类图片" width="200">
            <template v-slot="scope">
              <img :src="getServerUrl()+'/image/bigType/'+scope.row.image" width="80" height="80"/>
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="商品大类描述"/>
          <el-table-column prop="action" label="操作" width="300">
            <template v-slot="scope">
              <el-button type="success" @click="handleChangeImage(scope.row)">更换图片</el-button>
              <el-button type="primary" :icon="Edit" @click="handleDialogValue(scope.row)"></el-button>
              <el-button type="danger" :icon="Delete" @click="handleDelete(scope.row.id)"></el-button>
            </template>
    
          </el-table-column>
    
        </el-table>
    
        <el-pagination
          v-model:currentPage="queryForm.pageNum"
          :page-sizes="[10, 20, 30, 40,50]"
          :page-size="queryForm.pageSize"
          :small="small"
          :disabled="disabled"
          :background="background"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
      </el-card>
      <Dialog v-model="dialogVisible" :dialogTitle="dialogTitle" @initBigTypeList="initBigTypeList" :id="id"/>
      <ImageDialog v-model="imageDialogVisible" :imageDialogValue="imageDialogValue" @initBigTypeList="initBigTypeList"/>
    </template>
    
    <script setup>
    import {Search,Edit,Delete } from '@element-plus/icons-vue'
    import { ref } from 'vue'
    import  axios from '@/util/axios'
    import {getServerUrl} from "@/config/sys";
    import Dialog from './components/dialog'
    import ImageDialog from './components/imageDialog'
    import {ElMessageBox,ElMessage} from 'element-plus'
    
    const queryForm=ref({
      query:'',
      pageNum:1,
      pageSize:10
    })
    
    const total=ref(0)
    
    const id=ref(-1)
    
    const tableData=ref([
    ])
    
    const imageDialogValue=ref({})
    
    const dialogTitle=ref('')
    
    const initBigTypeList=async()=>{
      console.log('xxx')
      const res=await axios.post("admin/bigType/list",queryForm.value);
      tableData.value=res.data.bigTypeList;
      total.value=res.data.total;
    }
    
    initBigTypeList();
    
    const dialogVisible=ref(false)
    
    const imageDialogVisible=ref(false)
    
    
    const handleSizeChange=(pageSize)=>{
      queryForm.value.pageNum=1;
      queryForm.value.pageSize=pageSize;
      initBigTypeList();
    }
    
    const handleCurrentChange=(pageNum)=>{
      queryForm.value.pageNum=pageNum;
      initBigTypeList();
    }
    
    
    const handleDialogValue = (row) => {
      if(row){
        id.value=row.id;
        console.log(id)
        dialogTitle.value="商品大类修改"
      }else{
        id.value=-1;
        dialogTitle.value="商品大类添加"
      }
      dialogVisible.value=true;
    }
    
    const handleDelete = (id) => {
    
      ElMessageBox.confirm(
        '您确定要删除这条记录吗?',
        '系统提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }
      )
        .then(async() => {
          console.log("id="+id)
          let res=await axios.get("admin/bigType/delete/"+id);
          if(res.data.code==0){
            ElMessage({
              type: 'success',
              message: '删除成功!',
            });
            initBigTypeList();
          }else{
            ElMessage({
              type: 'error',
              message: res.data.msg,
            });
          }
    
        })
        .catch(() => {
    
        })
    }
    
    // 更换图片处理
    const handleChangeImage = (row) => {
      imageDialogValue.value=JSON.parse(JSON.stringify(row));
      imageDialogVisible.value=true;
    }
    
    </script>
    
    <style lang="scss" scoped>
    
    
    .header{
      padding-bottom: 16px;
      box-sizing: border-box;
    }
    
    .el-pagination{
      padding-top: 15px;
      box-sizing: border-box;
    }
    
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
  • 相关阅读:
    【Nginx29】Nginx学习:代理模块(三)缓冲区与Cookie处理
    SpringBoot 自动配置
    pytest(10)-常用执行参数说明
    CDA数据分析——AARRR增长模型的介绍、使用
    java计算机毕业设计基于springboo+vue的心理健康管理网站(源代码+数据库+Lw文档)
    Cross-species regulatory sequence activity prediction
    lambda表达式(C++11)
    Google Earth Engine 教程——影像聚合分析水体分析
    【揭秘Vue】nextTick的神秘面纱:原理与作用一览无余!
    股票交易查询接口api新增哪些了特点?
  • 原文地址:https://blog.csdn.net/m0_68935893/article/details/134273032