Riku
2024-08-12 7c3c82d429f86358142adceb080e8922f6a18aa0
设备信息管理模块

设备信息管理模块
已修改14个文件
157 ■■■■■ 文件已修改
app.json 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/dataMonitorDeviceType.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/dataProductionDeviceType.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/dataTreatmentDeviceType.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
components/form/index.js 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
components/form/index.wxml 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
components/picker/location-picker/index.json 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/inspection/scene/info/device-info-items.js 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/inspection/scene/info/device-info/index.js 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/inspection/scene/info/device-info/index.wxml 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/inspection/scene/info/device-info/index.wxss 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/inspection/scene/info/devicelist-proxy.js 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/inspection/scene/info/index.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
project.private.config.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app.json
@@ -71,6 +71,7 @@
    "t-cell-group": "tdesign-miniprogram/cell-group/cell-group",
    "t-collapse": "tdesign-miniprogram/collapse/collapse",
    "t-collapse-panel": "tdesign-miniprogram/collapse-panel/collapse-panel",
    "t-cascader": "tdesign-miniprogram/cascader/cascader",
    "t-dialog": "tdesign-miniprogram/dialog/dialog",
    "t-tabs": "tdesign-miniprogram/tabs/tabs",
    "t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel",
common/dataMonitorDeviceType.js
@@ -54,7 +54,7 @@
    case '6':
      return vocDeviceType;
    default:
      return dustDeviceTypebreak;
      return dustDeviceType;
  }
}
common/dataProductionDeviceType.js
@@ -54,7 +54,7 @@
    case '6':
      return vocDeviceType;
    default:
      return dustDeviceTypebreak;
      return dustDeviceType;
  }
}
common/dataTreatmentDeviceType.js
@@ -54,7 +54,7 @@
    case '6':
      return vocDeviceType;
    default:
      return dustDeviceTypebreak;
      return dustDeviceType;
  }
}
components/form/index.js
@@ -40,9 +40,6 @@
    onSwitchChange(e) {
      const { index } = e.currentTarget.dataset;
      const { value } = e.detail;
      // const { formArray } = this.data;
      // formArray[index].value = value;
      // this.setData({ formArray });
      this.setData({
        [`formArray[${index}].value`]: value,
      });
@@ -57,6 +54,7 @@
      const { label, value } = e.detail;
      this.setData({
        [`formArray[${index}].visible`]: false,
        [`formArray[${index}]._value`]: value,
        [`formArray[${index}].value`]: {
          label: label[0],
          value: value[0],
@@ -75,9 +73,18 @@
      this.setData({ [`formArray[${index}].visible`]: true });
    },
    onCascaderChange(e) {
      const { index } = e.currentTarget.dataset;
      const { selectedOptions, value } = e.detail;
      console.log(selectedOptions);
      console.log(value);
      const note = this._note(selectedOptions);
      const v = selectedOptions.map(v => {
        return { label: v.label, value: v.value };
      });
      this.setData({
        [`formArray[${index}].visible`]: false,
        [`formArray[${index}]._value`]: value,
        [`formArray[${index}].note`]: note,
        [`formArray[${index}].value`]: v,
      });
    },
    // 保存
@@ -85,7 +92,7 @@
      const formObj = {};
      this.data.formArray.forEach(e => {
        if (e.inputType == 'picker') {
          formObj[e.name] = e.value.value;
          formObj[e.name] = e.value ? e.value.value : e.value;
        } else {
          formObj[e.name] = e.value;
        }
@@ -100,7 +107,7 @@
    _note(v) {
      let note = '';
      v.forEach(o => {
        if (note != o.label && o.value > 0) {
        if (note != o.label) {
          if (note != '') {
            note += '/';
          }
components/form/index.wxml
@@ -1,4 +1,4 @@
<block wx:for="{{formArr}}" wx:key="index">
<block wx:for="{{formArray}}" wx:key="index">
  <block wx:if="{{item.inputType == 'text'}}">
    <t-input
      label="{{item.label}}"
@@ -19,9 +19,17 @@
    </t-cell>
  </block>
  <block wx:elif="{{item.inputType == 'picker'}}">
    <t-cell
      title="{{item.label}}"
      arrow
      hover
      note="{{item.value.label || item.placeholder}}"
      data-index="{{index}}"
      bind:click="showPicker"
    ></t-cell>
    <t-picker
      visible="{{item.visible}}"
      value="{{item.value}}"
      value="{{item._value}}"
      data-index="{{index}}"
      title="{{'选择' + item.label}}"
      cancelBtn="取消"
@@ -34,17 +42,16 @@
  </block>
  <block wx:elif="{{item.inputType == 'cascader'}}">
    <t-cell
      bordered="{{false}}"
      title="{{item.label}}"
      arrow
      hover
      note="{{item.note}}"
      note="{{item.note || item.placeholder}}"
      data-index="{{index}}"
      bind:click="showCascader"
    ></t-cell>
    <t-cascader
      visible="{{item.visible}}"
      value="{{item.value}}"
      value="{{item._value}}"
      options="{{item.options}}"
      sub-titles="{{item.cascaderTitles}}"
      title="{{'选择' + item.label}}"
components/picker/location-picker/index.json
@@ -1,6 +1,5 @@
{
  "component": true,
  "usingComponents": {
    "t-cascader": "tdesign-miniprogram/cascader/cascader"
  }
}
pages/inspection/scene/info/device-info-items.js
@@ -9,7 +9,7 @@
 * 生成一条表单条目
 * @param {String} _label 标签名称
 * @param {String} _name 字段名称
 * @param {String} _type 输入类型 (text: 输入框; switch: 切换按钮; picker: 下拉框选项)
 * @param {String} _type 输入类型 (text: 输入框; switch: 切换按钮; picker: 下拉框选项; cascader: 级联选择)
 * @param {Boolean} _required 是否为必填项
 * @param {Array} _options 当输入类型为picker时,提供可选项
 */
@@ -17,13 +17,15 @@
  return {
    required: _required,
    label: _label,
    placeholder: '请输入' + _label,
    placeholder: (_type == 'text' ? '请输入' : '请选择') + _label,
    name: _name,
    value: _type == 'switch' ? false : null,
    value: null,
    status: 'success',
    tips: _label + '不能为空',
    inputType: _type,
    options: _options,
    cascaderTitles: ['1', '2'],
    visible: false,
  };
}
pages/inspection/scene/info/device-info/index.js
@@ -14,42 +14,56 @@
  },
  onLoad(options) {
    if (options.type) {
      this.setData({ deviceType: parseInt(options.type) });
    this.getOpenerEventChannel().on('acceptDeviceData', data => {
      if (data) {
        const { scene, type, mode } = data;
      let barTitle, _formArr;
      switch (options.type) {
        case '0':
        switch (type) {
          case 0:
          barTitle = '新增监测设备';
          _formArr = monitorDeviceForm;
            _formArr = monitorDeviceForm(scene.typeid);
          break;
        case '1':
          case 1:
          barTitle = '新增治理设备';
          _formArr = treatmentDeviceForm;
            _formArr = treatmentDeviceForm(scene.typeid);
          break;
        case '2':
          case 2:
          barTitle = '新增生产设备';
          _formArr = productionDeviceForm;
            _formArr = productionDeviceForm(scene.typeid);
          break;
        default:
          barTitle = '设备信息';
          _formArr = monitorDeviceForm;
            _formArr = monitorDeviceForm(scene.typeid);
          break;
      }
      wx.setNavigationBarTitle({
        title: barTitle,
      });
      this.setData({ formArray: _formArr });
        this.setData({
          formArray: _formArr,
          scene,
          deviceType: type,
          mode,
        });
    }
    if (options.mode == 'add' || options.mode == 'update') {
      this.setData({ mode: options.mode });
    }
    });
  },
  // 提交表单
  submit(e) {
    const formArr = e.detail;
    const formObj = e.detail;
    const { mode, scene } = this.data;
    formObj.diSceneGuid = scene.guid;
    formObj.diSceneTypeId = scene.typeid;
    formObj.diTypeId = formObj._type[0].value;
    formObj.diSubtypeId = formObj._type[1].value;
    if (mode == 'add') {
      this.addDevice(formObj);
    } else {
      this.updateDevice(formObj);
    }
    console.log('submit');
    console.log(formArr);
    console.log(formObj);
  },
  // 取消表单
@@ -60,13 +74,16 @@
  // 新增设备信息
  addDevice(formObj) {
    const { deviceType } = this.data;
    formObj.diSceneGuid
    formObj.diSceneTypeId
    uploadDevice(formObj, deviceType).then(res => {
      console.log(res);
    });
  },
  // 更新设备信息
  updateDevice() {},
  updateDevice() {
    const { deviceType } = this.data;
    updateDevice(formObj, deviceType).then(res => {
      console.log(res);
    });
  },
});
pages/inspection/scene/info/device-info/index.wxml
@@ -1,22 +1,7 @@
<!-- <t-input label="站点名称" placeholder="请输入站点名称" model:value="{{diName}}" />
<t-input label="MN编号" placeholder="请输入MN编号" model:value="{{diMnCode}}" />
<t-input label="设备类型" placeholder="请输入设备类型" model:value="{{diType}}" />
<t-input label="供应商" placeholder="请输入供应商" model:value="{{diSupplier}}" />
<t-input label="运维商" placeholder="请输入运维商" model:value="{{diMaintainer}}" />
<t-cell title="是否上线">
  <t-switch
    model:value="{{diRunningStatus}}"
    defaultValue="{{true}}"
    label="{{['是', '否']}}"
    slot="note"
  />
</t-cell>
<t-cell title="是否拆除">
  <t-switch
    model:value="{{diRemoved}}"
    defaultValue="{{false}}"
    label="{{['是', '否']}}"
    slot="note"
  />
</t-cell> -->
<view class="page">
  <view class="page-header"> </view>
  <view class="page-container">
<t-form formArr="{{formArray}}" bind:submit="submit" bind:cancel="cancel"></t-form>
  </view>
  <view class="page-footer"></view>
</view>
pages/inspection/scene/info/device-info/index.wxss
@@ -1 +1,3 @@
/* pages/inspection/scene/info/device-info/index.wxss */
.page .page-container {
  padding: 0;
}
pages/inspection/scene/info/devicelist-proxy.js
@@ -32,9 +32,18 @@
    },
    addNewDevice(e) {
      const { type } = e.currentTarget.dataset;
      const { scene } = this.data;
      wx.navigateTo({
        url: `/pages/inspection/scene/info/device-info/index?type=${type}`,
      })
        url: `/pages/inspection/scene/info/device-info/index`,
        success: function (res) {
          // 通过 eventChannel 向被打开页面传送数据
          res.eventChannel.emit('acceptDeviceData', {
            type,
            scene,
            mode: 'add',
          });
        },
      });
    },
  },
});
pages/inspection/scene/info/index.js
@@ -5,7 +5,7 @@
  behaviors: [useDeviceList, useDeviceLocation],
  data: {
    // 场景基本信息
    sceneInfo:{},
    scene:{},
    // 监测设备信息
    monitorDevices:[],
    // 治理设备信息
project.private.config.json
@@ -1,6 +1,6 @@
{
  "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
  "projectname": "ep-law-abiding-manage",
  "projectname": "ep-law-abiding-manage-weixin",
  "setting": {
    "compileHotReLoad": true,
    "urlCheck": false