Role.vue 11.2 KB
Newer Older
wanli's avatar
wanli committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
<template>
  <a-page-header-wrapper title="查询表格">
    <a-card :bordered="false">
      <div class="tableList">
        <div class="tableListForm">
          <a-form v-show="!expandForm" layout="inline">
            <a-row :gutter="{ md: 8, lg: 24, xl: 48 }">
              <a-col :md="8" :sm="24">
                <a-form-item label="用户" v-decorator="['username']">
                  <a-input placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="性别" v-decorator="['gender']">
                  <a-select placeholder="请选择" style="width: 100%">
                    <a-option value="male">male</a-option>
                    <a-option value="female">female</a-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <span class="submitButtons">
                  <a-button type="primary" htmlType="submit"> 查询 </a-button>
                  <a-button :style="{ marginLeft: '8px' }"> 重置 </a-button>
                  <a :style="{ marginLeft: '8px' }" @click="toggleForm">
                    展开 <a-icon type="down" />
                  </a>
                </span>
              </a-col>
            </a-row>
          </a-form>
          <a-form v-show="expandForm" layout="inline">
            <a-row :gutter="{ md: 8, lg: 24, xl: 48 }">
              <a-col :md="8" :sm="24">
                <a-form-item label="用户" v-decorator="['username']">
                  <a-input placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="性别" v-decorator="['gender']">
                  <a-select placeholder="请选择" style="width: 100%">
                    <a-option value="male">male</a-option>
                    <a-option value="female">female</a-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="姓名" v-decorator="['name']">
                  <a-input placeholder="请输入" />
                </a-form-item>
              </a-col>
            </a-row>
            <a-row :gutter="{ md: 8, lg: 24, xl: 48 }">
              <a-col :md="8" :sm="24">
                <a-form-item label="时间" v-decorator="['registered']">
                  <a-range-picker style="width: 100%" />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="邮箱" v-decorator="['email']">
                  <a-input placeholder="请输入" />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="国籍" v-decorator="['nat']">
                  <a-input placeholder="请输入" />
                </a-form-item>
              </a-col>
            </a-row>
            <div style="overflow: hidden">
              <div :style="{ float: 'right', marginBottom: '24px' }">
                <a-button type="primary" htmlType="submit"> 查询 </a-button>
                <a-button :style="{ marginLeft: '8px' }"> 重置 </a-button>
                <a :style="{ marginLeft: '8px' }" @click="toggleForm">
                  收起 <a-icon type="up" />
                </a>
              </div>
            </div>
          </a-form>
        </div>
        <div class="tableListOperator">
          <a-button icon="plus" type="primary"> 新建 </a-button>
          <span v-show="selectedRowKeys.length > 0">
            <a-button>批量操作</a-button>
            <!-- <a-dropdown overlay={menu}>
                  <a-button>
                    更多操作 <icon type="down" />
                  </a-button>
                </a-dropdown> -->
          </span>
        </div>
        <!-- <StandardTable
              selectedRows={selectedRows}
              loading={loading}
              data={data}
              columns={this.columns}
              onSelectRow={this.handleSelectRows}
              onChange={this.handleStandardTableChange}
            /> -->
        <a-table
          :columns="columns"
          :rowKey="(record) => record.login.uuid"
          :dataSource="users.data"
          :pagination="users.pagination"
          :loading="loading"
          @change="handleTableChange"
        >
          <!-- :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" -->
          <template slot="login" slot-scope="login">
            {{ login.username }}
          </template>
          <template slot="name" slot-scope="name">
            {{ name.first }} {{ name.last }}
          </template>
          <template slot="registered" slot-scope="registered">
            {{ registered.date }} ({{ registered.age }})
          </template>
          <template
            slot="expandedRowRender"
            slot-scope="record"
            style="margin: 0"
          >
            <p :style="[sya, syb]">
              <a-avatar
                :src="record.picture.large"
                shape="square"
                :size="128"
              />
            </p>
            <p :style="[sya]">Personal</p>
            <a-row>
              <a-col :span="6">
                <a-description-item
                  title="Name"
                  :content="record.name.first + ' ' + record.name.last"
                />
              </a-col>
              <a-col :span="6">
                <a-description-item
                  title="Account"
                  :content="record.login.username"
                />
              </a-col>
              <a-col :span="6">
                <a-description-item
                  title="City"
                  :content="record.location.city"
                />
              </a-col>
              <a-col :span="6">
                <a-description-item
                  title="Postcode"
                  :content="record.location.postcode"
                />
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="6">
                <a-description-item title="Country" :content="record.nat" />
              </a-col>
              <a-col :span="6">
                <a-description-item
                  title="Birthday"
                  :content="record.dob.date + ' (' + record.dob.age + ')'"
                />
              </a-col>
              <a-col :span="12">
                <a-description-item
                  title="Timezone"
                  :content="record.location.timezone.description"
                />
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12"> </a-col>
              <a-col :span="12"> </a-col>
            </a-row>
            <a-divider />
            <p :style="[sya]">Contacts</p>
            <a-row>
              <a-col :span="6">
                <a-description-item title="Email" :content="record.email" />
              </a-col>
              <a-col :span="6">
                <a-description-item title="Cell" :content="record.cell" />
              </a-col>
              <a-col :span="6">
                <a-description-item title="Phone" :content="record.phone" />
              </a-col>
              <a-col :span="6">
                <a-description-item
                  title="Coordinates"
                  :content="
                    record.location.coordinates.latitude +
                    ' ' +
                    record.location.coordinates.longitude
                  "
                />
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="12">
                <a-description-item
                  title="Registered"
                  :content="
                    record.registered.date + ' (' + record.registered.age + ')'
                  "
                />
              </a-col>
            </a-row>
          </template>
          <template slot="action" slot-scope="text, record">
            <a href="javascript:;">查看</a>
            <a-divider type="vertical" />
            <a href="javascript:;">配置</a>
          </template>
        </a-table>
      </div>
    </a-card>
  </a-page-header-wrapper>
</template>

<script>
import {
  Avatar,
  Row,
  Col,
  Card,
  List,
  Button,
  Form,
  Icon,
  Table,
  Divider,
  Dropdown,
  Input,
  Select,
  DatePicker,
} from "ant-design-vue";
import PageHeaderWrapper from "@/components/PageHeaderWrapper";
import DescriptionItem from "@/components/DescriptionItem";
const columns = [
  {
    title: "用户名",
    dataIndex: "login",
    sorter: true,
    width: "12%",
    scopedSlots: { customRender: "login" },
  },
  {
    title: "姓名",
    dataIndex: "name",
    sorter: true,
    width: "15%",
    scopedSlots: { customRender: "name" },
  },
  {
    title: "性别",
    dataIndex: "gender",
    filters: [
      { text: "Male", value: "male" },
      { text: "Female", value: "female" },
    ],
  },
  {
    title: "邮箱",
    dataIndex: "email",
  },
  {
    title: "国籍",
    dataIndex: "nat",
  },
  {
    title: "Registered",
    dataIndex: "registered",
    scopedSlots: { customRender: "registered" },
  },
  {
    title: "Action",
    key: "action",
    scopedSlots: { customRender: "action" },
  },
];
import { mapGetters } from "vuex";
export default {
  data: () => ({
    expandForm: false,
    selectedRowKeys: [],
    columns,
    sya: {
      fontSize: "16px",
      color: "rgba(0,0,0,0.85)",
      lineHeight: "24px",
      display: "block",
      marginBottom: "16px",
    },
    syb: {
      marginBottom: "24px",
    },
  }),
  async asyncData({ store, route }, config = { results: 15 }) {
    await store.dispatch("frontend/openapi/getUsers", {
      ...config,
      path: route.path,
    });
  },
  computed: {
    ...mapGetters({
      loading: "frontend/openapi/loading",
      users: "frontend/openapi/getUsers",
    }),
  },
  components: {
    APageHeaderWrapper: PageHeaderWrapper,
    AAvatar: Avatar,
    ARow: Row,
    ACol: Col,
    ACard: Card,
    ACardGrid: Card.Grid,
    ACardMeta: Card.Meta,
    AList: List,
    AButton: Button,
    AForm: Form,
    AFormItem: Form.Item,
    AIcon: Icon,
    ATable: Table,
    ADescriptionItem: DescriptionItem,
    ADivider: Divider,
    ADropdown: Dropdown,
    AInput: Input,
    ASelect: Select,
    AOption: Select.Option,
    ARangePicker: DatePicker.RangePicker,
  },
  methods: {
    toggleForm() {
      this.expandForm = !this.expandForm;
    },
    onSelectChange(selectedRowKeys) {
wanli's avatar
wanli committed
340
      window.console.log("selectedRowKeys changed: ", selectedRowKeys);
wanli's avatar
wanli committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
      this.selectedRowKeys = selectedRowKeys;
    },
    handleTableChange(pagination, filters, sorter) {
      const pager = { ...this.users.pagination };
      pager.current = pagination.current;
      this.users.pagination = pager;
      this.$options.asyncData(
        { store: this.$store, route: this.$route },
        {
          results: pagination.pageSize,
          page: pagination.current,
          sortField: sorter.field,
          sortOrder: sorter.order,
          ...filters,
        }
      );
    },
  },
  mounted() {
    this.$options.asyncData(
      { store: this.$store, route: this.$route },
      { results: 15 }
    );
  },
};
</script>
<style lang="less">
wanli's avatar
wanli committed
368
@import url("styles/tableList.less");
wanli's avatar
wanli committed
369
</style>