123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <template>
- <view>
- <connectingDevice ref="refCD" @onFeedback="onFeedback" />
- <block v-for="(item, index) in list" :key="item.w_functionid">
- <view
- v-if="item.paramName != 'E013'"
- class="item"
- :hover-class="item.inputType == 'switch' ? '' : 'navigator-hover'"
- @click="item.inputType == 'switch' ? '' : onClick(item)"
- >
- <view class="label">
- {{ item.funcname }}
- <block v-if="item.inputType == 'radio'">
- {{ radioName(item) }}
- </block>
- <block v-if="item.inputType != 'switch'">
- :{{
- item.inputType == "radio"
- ? item.showValue || "未设置"
- : item.params.lastvalue || "未设置"
- }}
- <text v-if="item.params.unit" style="margin-left: 2px"
- >({{ item.params.unit }})</text
- >
- </block>
- </view>
- <view>
- <block v-if="item.inputType == 'switch'">
- <u-switch
- :value="item.params.lastvalue == 1"
- asyncChange
- size="24"
- :loading="item.loading"
- @change="changeSwitch(item, index)"
- />
- </block>
- <block v-else>
- <u-loading-icon v-if="item.loading" />
- <text
- v-else
- class="iconfont icon-a-wodetiaozhuan"
- style="color: #fff"
- />
- </block>
- </view>
- </view>
- </block>
- <My_input mode="1" ref="MyInput" @sendMsg="onSendMsg" />
- </view>
- </template>
- <script>
- export default {
- name: "prodnum-FW01",
- components: {},
- props: {
- control: Object,
- },
- data() {
- return {
- list: [],
- };
- },
- watch: {
- control: function (newVal) {
- if (newVal) {
- let names = [];
- for (const key in newVal.function) {
- names.push(key);
- }
- this.list = this.__proto__.getControlItem(names, newVal, {
- 安装位置: "radio",
- 第二域名: "string",
- });
- setTimeout(() => {
- this.authentication(this);
- }, 100);
- this.$refs.refCD.init();
- }
- },
- },
- methods: {
- authentication(that) {
- try {
- uni.showLoading({
- title: "身份验证中...",
- mask: true,
- });
- const E013 = that.list.find((v) => v.paramName == "E013");
- if (E013) {
- that.$refs.refCD.send({ password: that.control.bluetoothcode }, E013);
- }
- } catch (error) {
- console.error("下发身份验证失败", error);
- }
- },
- onClick(item) {
- this.$refs.MyInput.openInput(item);
- },
- radioName(item) {
- try {
- item.showValue =
- item.params.options.find((v) => v.value == item.params.lastvalue)
- .label || "";
- } catch (error) {
- item.showValue;
- }
- return "";
- },
- changeSwitch(item, index) {
- const value = item.params.lastvalue == 1 ? 0 : 1;
- let msg = {
- d: {
- [item.params.param]: value,
- },
- };
- this.$refs.refCD.send(msg, item);
- this.$set(this.list[index], "loading", true);
- },
- onSendMsg(w_functionid, d) {
- const index = this.list.findIndex((v) => v.w_functionid == w_functionid);
- let msg = {
- d,
- };
- this.$refs.refCD.send(msg, this.list[index]);
- this.$set(this.list[index], "loading", true);
- },
- onFeedback(res) {
- console.log("onFeedback", res);
- const index = res.node
- ? this.list.findIndex((v) => res.node == v.paramName)
- : this.list.findIndex((v) => v.msgid == res.msgid);
- uni.hideLoading();
- let that = this;
- if (index != -1) {
- let item = this.list[index];
- let MyInput = this.$refs.MyInput;
- MyInput.loading = false;
- if (res.status == 1) {
- if (res.node) {
- item.params.lastvalue = res.v;
- } else if (res.msgid) {
- try {
- item.params.lastvalue = item.msg.d[item.params.param];
- } catch (error) {}
- }
- MyInput.show = false;
- MyInput.stepIsCalculate = null;
- } else if (res.status == 0) {
- if (item.paramName == "E013") {
- uni.showModal({
- content: `身份验证失败`,
- confirmText: "重新验证",
- cancelText: "断开连接",
- complete: ({ confirm, cancel }) => {
- if (confirm) {
- that.authentication(that);
- }
- if (cancel) {
- uni.closeBLEConnection({
- deviceId: that.connected,
- });
- that.$Http.setDetailMode(0);
- }
- },
- });
- } else {
- uni.showModal({
- title: "失败",
- content: `“${item.funcname}”设置失败`,
- showCancel: false,
- });
- }
- }
- MyInput.$refs.uModal.loading = false;
- delete item.loading;
- // delete item.msgid;
- // delete item.msg;
- this.$set(this.list, index, item);
- console.log(item);
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin: 10px 0;
- box-sizing: border-box;
- padding: 16px 20px;
- border-radius: 6px;
- background: rgba($color: #ffffff, $alpha: 0.1);
- .label {
- color: #fff;
- font-size: 14px;
- width: 230px;
- }
- }
- </style>
|