2021-06-08 记录一些工作遇到的问题总结

本文介绍如何使用游标处理两种场景:1. 将int类型的time字段转换为datetime并更新到新字段,2. 复制旧表数据到新表中。还涉及Vue的反向代理配置和常见问题解决方案。

游标的使用

例1:当一个时间字段a为int类型,当转换为datetime类型时,其会数据格式和datetime不符出现错误。解决思想不改变a的类型。新建一个字段为b (datetime) 使用游标将数据int转换datetime更新到b字段中

begin
       declare stop_flag int DEFAULT 0;
	declare inttime INT;
  DECLARE datet datetime;
  DECLARE tid BIGINT;

	declare cur1 cursor for SELECT id,real_name_day,FROM_UNIXTIME(real_name_day) FROM `user`;
       declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop_flag=1;  
       open cur1;
       fetch cur1 into tid,inttime,datet;
       while stop_flag<>1 DO
	         UPDATE `user` SET real_name_time=datet WHERE id=tid;
           fetch cur1 into tid,inttime,datet;
       end while;
       close cur1;
end

例二:就是新建一张表d ,d的某些字段是旧表c的将c的数据复制到d表上,使用游标

begin
       declare stop_flag int DEFAULT 0;
	declare u_oid INT(10);
	declare u_provider int(1);
	declare u_adcode INT(10);
  declare u_level VARCHAR(20);
  declare u_provider_bonus_day int(12);
  declare u_update_at datetime;

	declare cur1 cursor for select oid,provider,adcode,`level`,provider_bonus_day,updated_at from `user`;
       declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop_flag=1;  
       open cur1;

       fetch cur1 into u_oid,u_provider,u_adcode,u_level,u_provider_bonus_day,u_update_at;
       while stop_flag<>1 DO
	    insert into city_service_provider(id,provider_state,provider_ad_code,provider_level,provider_end_time,updated_at) values(u_oid,u_provider,u_adcode,u_level,u_provider_bonus_day,u_update_at);
           fetch cur1 into u_oid,u_provider,u_adcode,u_level,u_provider_bonus_day,u_update_at;
       end while;
       close cur1;
end

vue 反向代理

// 设置反向代理,前端请求默认发送到 http://localhost:8443/api
var axios = require('axios')
axios.defaults.baseURL = 'http://localhost:8443/api'
// 全局注册,之后可在其他组件中通过 this.$axios 发送数据
Vue.prototype.$axios = axios
Vue.config.productionTip = false

vue跨域问题

 proxyTable: {
      '/api': {
        target: 'http://localhost:8443',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }

js的弹窗

//弹窗
	function Toast(msg,duration){
	  duration=isNaN(duration)?3000:duration;
	  var m = document.createElement('div');
	  m.innerHTML = msg;
	  m.style.cssText="max-width:40%;min-width: 70px;padding:0 14px;height: 20px;color: rgb(255, 255, 255);line-height: 20px;text-align: center;border-radius: 4px;position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 9999999999;background: rgba(0, 0, 0,.7);font-size: 8px;";
	  document.body.appendChild(m);
	  setTimeout(function() {
	    var d = 0.5;
	    m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
	    m.style.opacity = '0';
	    setTimeout(function() { document.body.removeChild(m) }, d * 1000);
	  }, duration);
	}

数据库数据展示列表中显示不同的问题

 <el-table-column label="状态" width="120px" align="center" :formatter="stateFormat">
      </el-table-column>


      stateFormat(row, column) {
        if (row.status === 1) {
          return '止盈'
        } else if (row.status === -1) {
          return '止损'
        }
      },

使用echat 树遇到的问题

 drawLine(){
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
        var datas = [{
          userId:this.superUser.userId,
          phone: this.superUser.phone,
          nickName: this.superUser.nickName,
          symbol:"image://"+this.superUser.avatar,
          collapsed:false,
          children: [{
            userId:this.user.userId,
            phone: this.user.phone,
            nickName: this.user.nickName,
            symbol:"image://"+this.user.avatar,
            collapsed:false,
            children: this.list
          }]
        }];
        var option = {
          tooltip: {
            show:true,
            data:datas,
            trigger: 'item',
            triggerOn: 'mousemove',
            formatter: function (param) {
              return `昵称: `+param.data.nickName+`ID号:`+param.data.phone
            }

          },
          series: [{
            type: 'tree', // 设置树图
            name: 'xxxx',
            orient: 'TB', // 树图发散的方向,(只有在 layout = 'orthogonal' 的时候,该配置项才生效)对应有 水平 方向的 从左到右,从右到左;以及垂直方向的 从上到下,从下到上。取值分别为 'LR' , 'RL', 'TB', 'BT'。注意,之前的配置项值 'horizontal' 等同于 'LR', 'vertical' 等同于 'TB'。
            data: datas, // 树图所需要的的数据
            left: '0%',
            right: '0%',
            layout: 'orthogonal', // 正交布局(水平布局)
            symbolSize: [80, 80], // 标记大小
            initialTreeDepth: 1, // 树图层级
            expandAndCollapse: true,
            lineStyle: {
              curveness: 0, // 树图边的曲度
            },
            label: {
              offset:[0,35,0,0],//调整位置
              formatter: function (param) {
                return `{div|`+param.data.nickName+`}\n{div|`+param.data.phone+`}\n{a|按钮}`

              },
              rich:{
                div:{
                  width: 70,
                  color: "#333",
                  fontSize: 8,
                  backgroundColor:" #4986F7",
                  color:" #fff",
                  padding: [4, 5, 4, 5],
                  wordBreak: "break-all",
                  align:"center"
                },
                a:{
                  with:30,
                  height:8,
                  backgroundColor:" #4986F7",
                  borderRadius: 20,
                  padding: [4, 7, 4, 7],
                  color:" #fff",
                  fontSize: 8,
                  align:"center"
                },
                img:{
                  with:30,
                  height:30,
                },
              }
            },
            emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              },
          }]
        }
        myChart.clear();
        myChart.setOption(option);
        let conation = document.getElementById("main");
        let allNodes = 0;
        let nodes = myChart._chartsViews[0]._data._graphicEls
        for(var i =0;i<nodes.length;i++){
          let node = nodes[i]
          if(node == undefined){
            continue
          }else{
            allNodes++
          }
        }

        conation.style.width=100*allNodes +'px'   //自行调节

        conation.style.height=100*allNodes +'px'   //自行调节
        myChart.resize()

        myChart.on('mousedown', (params)=>{   //点击是展开收放还是其他功能
          if (params.event.target.culling === true){
            const userId = params.data.userId;
            const curNode = myChart._chartsViews[0]._data.tree._nodes.find(item => {
              return item.userId === userId;
            });
            const depth = curNode.depth;
            const curIsExpand = curNode.isExpand;
            myChart._chartsViews[0]._data.tree._nodes.forEach((item, index) => {
              if (item.depth === depth && item.userId !== userId && !curIsExpand) {
                item.isExpand = false;
              }
            });
            console.log("节点");
          }else if(params.event.target.culling === false){
            this.rightClick(params.data.userId)
            console.log("点击了label");
          }
        });

      },

vue提示

 this.$notify({
                  title: '成功',
                  message: res.msg,
                  type: 'success',
                  duration: 2000
                })
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值