add SwitchBtn 组件
This commit is contained in:
		@@ -39,7 +39,7 @@
 | 
			
		||||
    <script>
 | 
			
		||||
    // window.SITE_CONFIG['apiURL'] = 'http://192.168.1.103:8080/pms-am';
 | 
			
		||||
    // window.SITE_CONFIG['apiURL'] = 'http://192.168.1.49:8080/pms-am'; // tengyun
 | 
			
		||||
    window.SITE_CONFIG['apiURL'] = 'http://192.168.1.62:8080/pms-am'; // tengyun
 | 
			
		||||
    window.SITE_CONFIG['apiURL'] = 'http://192.168.1.62:8080/pms-am'; // tao
 | 
			
		||||
    </script>
 | 
			
		||||
  <% } %>
 | 
			
		||||
  <!-- 集成测试环境 -->
 | 
			
		||||
 
 | 
			
		||||
@@ -1,2 +1,55 @@
 | 
			
		||||
// 表格中的开关
 | 
			
		||||
export default {}
 | 
			
		||||
// import i18n from '@/i18n'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  name: "SwitchBtn",
 | 
			
		||||
  props: {
 | 
			
		||||
    injectData: {
 | 
			
		||||
      type: Object,
 | 
			
		||||
      default: () => ({}),
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    const elSwitchModel = this.injectData.enabled ? true : false
 | 
			
		||||
    return {
 | 
			
		||||
      elSwitchModel
 | 
			
		||||
    };
 | 
			
		||||
  },
 | 
			
		||||
  mounted() {
 | 
			
		||||
    // console.log("[SwitchBtn] injectData: ", this.injectData);
 | 
			
		||||
  },
 | 
			
		||||
  computed: {
 | 
			
		||||
    status: {
 | 
			
		||||
      get() {
 | 
			
		||||
        return this.elSwitchModel
 | 
			
		||||
      },
 | 
			
		||||
      set(val) {
 | 
			
		||||
        this.elSwitchModel = val
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    // 发射事件
 | 
			
		||||
    emit(booleanValue) {
 | 
			
		||||
      const { id, code } = this.injectData
 | 
			
		||||
      this.$emit('emit-data', { type: 'status', data: { id, code, enabled: booleanValue ? '1' : '0' } })
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  render: function (h) {
 | 
			
		||||
    var self = this 
 | 
			
		||||
    return h(
 | 
			
		||||
      "el-switch",
 | 
			
		||||
      {
 | 
			
		||||
        props: {
 | 
			
		||||
          value: self.status,
 | 
			
		||||
        },
 | 
			
		||||
        on: {
 | 
			
		||||
          change: function (val) {
 | 
			
		||||
            self.status = val
 | 
			
		||||
            self.emit(val)
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    );
 | 
			
		||||
  },
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,6 @@ import moment from 'moment'
 | 
			
		||||
 | 
			
		||||
export const dictFilter = dictTypeId => {
 | 
			
		||||
	return val => {
 | 
			
		||||
		console.log('ddd', (JSON.parse(localStorage.getItem('dictList')))[dictTypeId])
 | 
			
		||||
		return JSON.parse(localStorage.getItem('dictList'))[dictTypeId].find(item => item.dictValue === val)?.dictLabel || '-'
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -197,6 +197,23 @@ export default {
 | 
			
		||||
          this.openDialog(data, true);
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
        case "status": {
 | 
			
		||||
          // TODO: 类似于这种字符串,可以统一集中到一个文件里
 | 
			
		||||
          const { id, code, enabled } = data;
 | 
			
		||||
          // 更改状态,更改状态需要 id 和 code 然后是 状态 enabled
 | 
			
		||||
          this.$http
 | 
			
		||||
            .put(this.urls.base, {
 | 
			
		||||
              id,
 | 
			
		||||
              code,
 | 
			
		||||
              enabled,
 | 
			
		||||
            })
 | 
			
		||||
            .then(({ data: res }) => {
 | 
			
		||||
              if (res.code === 0) {
 | 
			
		||||
                // do nothing
 | 
			
		||||
              }
 | 
			
		||||
            });
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
import TableOperaionComponent from "@/components/noTemplateComponents/operationComponent";
 | 
			
		||||
import StatusComponent from "@/components/noTemplateComponents/statusComponent";
 | 
			
		||||
import switchBtn from "@/components/noTemplateComponents/switchBtn";
 | 
			
		||||
import request from "@/utils/request";
 | 
			
		||||
import { dictFilter } from '@/utils/filters'
 | 
			
		||||
 | 
			
		||||
@@ -7,8 +7,8 @@ export default function () {
 | 
			
		||||
  const tableProps = [
 | 
			
		||||
    { prop: "name", label: "料仓名称" },
 | 
			
		||||
    { prop: "code", label: "料仓编码" },
 | 
			
		||||
    { prop: "typeDictValue", label: "料仓类型", filter: dictFilter('liangcang') },
 | 
			
		||||
    { prop: "status", label: "产线状态", subcomponent: StatusComponent }, // subcomponent
 | 
			
		||||
    { prop: "typeDictValue", label: "料仓类型", filter: dictFilter('liaocang') },
 | 
			
		||||
    { prop: "status", label: "状态", subcomponent: switchBtn }, // subcomponent
 | 
			
		||||
    { prop: "description", label: "描述" },
 | 
			
		||||
    { prop: "remark", label: "备注" },
 | 
			
		||||
    {
 | 
			
		||||
@@ -78,8 +78,9 @@ export default function () {
 | 
			
		||||
            prop: "typeDictValue",
 | 
			
		||||
            // fetchData: () => this.$http.get("/pms/factory/page", { params: { limit: 999, page: 1 } }),
 | 
			
		||||
            options: [
 | 
			
		||||
              { label: '中间仓', value: 0 },
 | 
			
		||||
              { label: '日料仓', value: 1 },
 | 
			
		||||
              // TODO: 或许映射可以全权交给数据字典
 | 
			
		||||
              { label: '中间仓', value: '0' },
 | 
			
		||||
              { label: '日料仓', value: '1' },
 | 
			
		||||
            ],
 | 
			
		||||
            rules: { required: true, message: "not empty", trigger: "change" },
 | 
			
		||||
          },
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user