gaoluyang
2 天以前 fe631515b71782a10a750874f6d4582fe027cd22
src/views/system/user/authRole.vue
@@ -17,7 +17,7 @@
      </el-form>
      <h4 class="form-header h4">角色信息</h4>
      <el-table v-loading="loading" :row-key="getRowKey" @row-click="clickRow" ref="roleRef" @selection-change="handleSelectionChange" :data="roles.slice((pageNum - 1) * pageSize, pageNum * pageSize)">
      <el-table v-loading="loading" :row-key="getRowKey" @row-click="clickRow" ref="roleRef" @selection-change="handleSelectionChange" :data="roles.slice((pageNum - 1) * pageSize, pageNum * pageSize)" stripe>
         <el-table-column label="序号" width="55" type="index" align="center">
            <template #default="scope">
               <span>{{ (pageNum - 1) * pageSize + scope.$index + 1 }}</span>
@@ -46,78 +46,78 @@
</template>
<script setup name="AuthRole">
import { getAuthRole, updateAuthRole } from "@/api/system/user";
import { getAuthRole, updateAuthRole } from "@/api/system/user"
const route = useRoute();
const { proxy } = getCurrentInstance();
const route = useRoute()
const { proxy } = getCurrentInstance()
const loading = ref(true);
const total = ref(0);
const pageNum = ref(1);
const pageSize = ref(10);
const roleIds = ref([]);
const roles = ref([]);
const loading = ref(true)
const total = ref(0)
const pageNum = ref(1)
const pageSize = ref(10)
const roleIds = ref([])
const roles = ref([])
const form = ref({
  nickName: undefined,
  userName: undefined,
  userId: undefined
});
})
/** 单击选中行数据 */
function clickRow(row) {
  if (checkSelectable(row)) {
    proxy.$refs["roleRef"].toggleRowSelection(row);
    proxy.$refs["roleRef"].toggleRowSelection(row)
  }
};
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  roleIds.value = selection.map(item => item.roleId);
};
  roleIds.value = selection.map(item => item.roleId)
}
/** 保存选中的数据编号 */
function getRowKey(row) {
  return row.roleId;
};
  return row.roleId
}
// 检查角色状态
function checkSelectable(row) {
  return row.status === "0" ? true : false;
};
  return row.status === "0" ? true : false
}
/** 关闭按钮 */
function close() {
  const obj = { path: "/system/user" };
  proxy.$tab.closeOpenPage(obj);
};
  const obj = { path: "/system/user" }
  proxy.$tab.closeOpenPage(obj)
}
/** 提交按钮 */
function submitForm() {
  const userId = form.value.userId;
  const rIds = roleIds.value.join(",");
  const userId = form.value.userId
  const rIds = roleIds.value.join(",")
  updateAuthRole({ userId: userId, roleIds: rIds }).then(response => {
    proxy.$modal.msgSuccess("授权成功");
    close();
  });
};
    proxy.$modal.msgSuccess("授权成功")
    close()
  })
}
(() => {
  const userId = route.params && route.params.userId;
  const userId = route.params && route.params.userId
  if (userId) {
    loading.value = true;
    loading.value = true
    getAuthRole(userId).then(response => {
      form.value = response.user;
      roles.value = response.roles;
      total.value = roles.value.length;
      form.value = response.user
      roles.value = response.roles
      total.value = roles.value.length
      nextTick(() => {
        roles.value.forEach(row => {
          if (row.flag) {
            proxy.$refs["roleRef"].toggleRowSelection(row);
            proxy.$refs["roleRef"].toggleRowSelection(row)
          }
        });
      });
      loading.value = false;
    });
        })
      })
      loading.value = false
    })
  }
})();
})()
</script>