EE308FZ_First Assignment_Front-end and Back-end Separation Contacts Programming

Assignment 1Front-end and Back-end Separation Contacts Programming
Course for This Assignment2401_MU_SE_FZU
Assignment RequirementsFirst Assignment – Front-end and Back-end Separation Contacts Programming
NameMolan Xue
Student IDMU: 22125281 FZU:832201130
Objectives of This AssignmentUsing web frameworks or other platforms to implement a front-end and back-end separated contacts management system with basic functionalities like adding, modifying, and deleting contacts.
Other Reference1. WeChat Mini Program Design Guide 2. Javascript Style Guide 3. WeChat Developer Tools 4. The Art of Construction

1. Task Overview: Building a Digital Address Book

1.1 Task Description

Developing a Separated Address Book System
The first assignment focuses on creating a contact management system that emphasizes the separation of front-end and back-end functionalities. This assignment includes three core functions:

  1. Adding Contacts: Implement a feature that allows users to add contact information such as names and phone numbers. This data must be securely stored in a back-end database.
  2. Modifying Contacts: Ensure that contact information can be modified by retrieving data directly from the back-end database, with caching strictly prohibited.
  3. Deleting Contacts: Facilitate the deletion of contact information, requiring the operation to be executed directly through the back-end database.

After successfully implementing these basic functions, the project must be deployed to a cloud server, ensuring accessibility and usability.

1.2 Github Repository Link

1.3 Coding Standard Link

2. PSP Table

Personal Software Process StagesEstimated Time(minutes)Actual Time(minutes)
Planning180240
• Estimate180240
Development12601680
• Analysis180240
• Design Spec180240
• Design Review90120
• Coding Standard6080
• Design180240
• Coding480720
• Code Review6080
• Test3040
Reporting360480
• Test Repor90120
• Size Measurement6080
• Postmortem & Process Improvement Plan210280
Sum18002400

3. Product Presentation

3.1 User Interface

Firstly, find SoCiaLConTacT in my Recently Used Mini Programs section and click to enter.
Operation Process
You will see the following user interface:
User Interface
Currently, the data for the Mini Program Cloud Development Console is as follows:
Mini Program Cloud Development Console

3.2 Feature 1: Add

Click the Add New Contact button at the bottom of the screen:
Adding
The mini program will allow adding new contact information, and we can input and save the contact information to the user interface:
gif1
After adding the operation, the data in the Mini Program Cloud Development Console:
After adding

3.3 Feature 2: Modify

Click the Edit Contact button at the bottom of the screen:
Modifying
The mini program will allow modifying contact information:
gif2

After modifying the operation, the data in the Mini Program Cloud Development Console:
After modifying

3.4 Feature 3: Delete

Click the Delete Contact button at the bottom of the screen:
Deleting
The mini program will allow deleting contact information:
gif3

After deleting the operation, the data in the Mini Program Cloud Development Console:
After deleting

3.5 Feature 4: Upload Profile Picture

The mini program will allow uploading local photos to complete contact information:
gif4

4. Design Process

4.1 Functional Structure Diagram

Structure

4.2 Frontend Design

4.2.1 Requirement Analysis

The core functions of the mini program include:

  1. Display contact list, supporting grouping by letters.
  2. Provide a search function that allows real-time searching based on contact names.
  3. Add, edit, delete contacts and upload profile picture.
  4. Display detailed information of contacts, including profile picture, name, birthday, phone number, email, and address.

4.2.2 Interface Design

Design the interface of the mini program according to the requirements. The main interface includes:

  1. Home page (index. wxml): Contact list, alphabetical index, search box, add contact button.
  2. Contact Details Page (card. wxml): Display and edit the detailed information of individual contacts.
  3. Log page (logs. wxml): Display startup logs (optional feature).
Design Steps
Layout DesignUse (scroll view) to display the contact list and support scrolling.
Use the (navigator) component to link to the contact details page.
Design a floating letter index for quick and easy navigation.
Style DesignUse wxss files to define the overall color tone and layout style, such as setting margins, font size, background color, etc., to make the interface more beautiful and user-friendly.

4.2.3 Component Design

  1. Contact list component: responsible for displaying grouped contacts.
  2. Search component: Real time retrieval of user input and dynamic filtering of contact lists.
  3. Contact card component: used to display the basic information and operation buttons (add, modify, delete) of each contact.

4.2.4 Data Processing

  1. Use wx. cloud. database() to retrieve contact data from the cloud.
  2. Group contact data alphabetically and classify Chinese and English names.

4.2.5 Interaction Design

  1. Search Function: Monitor input events in the search box and filter contacts in real-time based on input content.
  2. Jump Function: Click on the contact name to jump to the contact details page, and pass the unique ID of the contact through the URL.

4.3 Backend Design

4.3.1 Cloud Development Environment Settings

  1. Choose a cloud development platform: Use WeChat Cloud for development, providing services such as cloud databases and cloud functions.
  2. Initialize cloud environment: In the entry file (index. js) of the mini program, use wx. cloud. init() to initialize the cloud development environment, specifying the cloud environment ID as mol-3gpukkfsaab8e2e7.

4.3.2 Database Structure Design

Determine the Data Model
Design a contacts collection to store contact information. Each contact document should include the following fields:
_Id: Unique identifier of the contact (automatically generated).
Name: The name (string) of the contact person.
Phone: Contact's phone number (string).
Email: Contact's email address (string, optional).
Address: Contact's address (string, optional).
Create a Cloud Database CollectionCreate a collection named contacts in the WeChat Cloud Development Console to ensure that the data model matches the design.

4.3.3 Design of Data Access Interface

AddingUse the cloud function addContact to handle requests to add new contacts.
In cloud functions, receive contact information from the client and call the contacts. add() method to add a new contact to the database.
ModifyingUse the cloud function updateContact to handle requests to update contacts.
Receive the id and new information of the contact to be updated, find the corresponding document in the database and update it.
DeletingUse the cloud function deleteContact to handle requests to delete contacts.
Receive the id of the contact to be deleted and delete the corresponding document from the database.

4.3.4 Interface Security Design

Permission Control:

  1. Ensure that only authenticated users can access data through user authentication in WeChat mini programs.
  2. Add logic to cloud functions to verify user login status and permissions.

4.3.5 Cloud Function Deployment and Testing

Deploying Cloud Functions: Deploy all designed cloud functions in the WeChat Cloud Development Console.
Functional testing:

  1. Use WeChat developer tools for interface testing to ensure that each cloud function can handle requests correctly and return expected results.
  2. Verify whether the operations of adding, deleting, modifying, and querying data are normal, and ensure that database operations comply with design requirements.

5. Implementation Process

5.1 Frontend Implementation

5.1.1 Homepage Implementation

  1. View layout:
  • Create homepage layout: Design the contact list structure in index.wxml and use thecomponent to wrap the contact list to support scrolling viewing.
<scroll-view class="contact" scroll-y="true" style="height:{{screenHeight}}rpx">
  <view class="search"></view>
  <block wx:for="{{filteredContacts}}" wx:key="letter">
    <view class="group" wx:if="{{item.group.length != 0}}" id="{{item.letter}}">
      <view class="header">{{item.letter}}</view>
      <navigator class="card" wx:for="{{item.group}}" wx:for-item="star" wx:key="*this" url="/pages/card/card?id={{star._id}}">
        <view class="name">{{star.name}}</view>
      </navigator>
    </view>
  </block>
</scroll-view>
  1. Search function:
  • Implement search box: Add a search input box in index.wxml to listen for user input.
<input type="text" bindinput="onSearchInput" placeholder="Search for a contact" />
  • Implement real-time filtering: Implement the onSearchInput method in index.js to retrieve input content and call the filterContacts method for filtering.
  1. Data loading:
  • Load contacts from cloud database: In the loadContactsFromDatabase method, use the cloud database API to retrieve contact data.
contactsCollection.get({
  success: res => {
    this.arrangeContact(res.data);
  },
  fail: err => {
    console.error('Failed to Retrieve Contacts:', err);
  }
});
  1. Data Processing and Grouping:
  • Organize contact data: In the arrangeContact method, group contacts based on letters and process Chinese and English names.
if (/^[\u4e00-\u9fa5]+$/.test(contactName[0])) {
  group.push(contactItem);
}

5.1.2 Implementation of Contact Details Page

  1. View Layout: Design and display detailed information of the contact in card-wxml, including name, phone number, email, etc.
<view class="contact-detail">
  <text>Name:{{contact.name}}</text>
  <text>Phone:{{contact.phone}}</text>
  <!-- Other Information -->
</view>
  1. Data binding: In card.exe, use the passed ID to retrieve detailed information of the specific contact from the cloud database.
const id = this.options.id;
contactsCollection.doc(id).get({
  success: res => {
    this.setData({ contact: res.data });
  }
});

5.1.3 Implementation of Add Contact Function

  1. View layout: Create an add contact page: Design an input form in addContact-wxml where users can enter information such as name, phone number, etc.
  2. Data submission: Implement the submission logic: In addContact. js, use wx. cloud. database(). collection (‘contacts’). add() to add the new contact to the cloud database.

5.2 Backend Implementation

5.2.1 Implemention of Adding Operation

// cloud/functions/addContact/index.js
const cloud = require('wx-server-sdk');

cloud.init();
const db = cloud.database();

exports.main = async (event, context) => {
  const { name, phone, email, address } = event;  // Retrieve contact information from the event
  try {
    return await db.collection('contacts').add({
      data: {
        name,
        phone,
        email,
        address
      }
    });
  } catch (e) {
    return {
      error: e
    };
  }
};

5.2.2 Implemention of Modifying Operation

// cloud/functions/updateContact/index.js
const cloud = require('wx-server-sdk');

cloud.init();
const db = cloud.database();

exports.main = async (event, context) => {
  const { id, name, phone, email, address } = event;  // Get the contact information to be modified
  try {
    return await db.collection('contacts').doc(id).update({
      data: {
        name,
        phone,
        email,
        address
      }
    });
  } catch (e) {
    return {
      error: e
    };
  }
};

5.2.3 Implemention of Deleting Operation

// cloud/functions/deleteContact/index.js
const cloud = require('wx-server-sdk');

cloud.init();
const db = cloud.database();

exports.main = async (event, context) => {
  const { id } = event;  // Get the contact ID to be deleted
  try {
    return await db.collection('contacts').doc(id).remove();
  } catch (e) {
    return {
      error: e
    };
  }
};

5.2.4 Call Cloud Functions

// Adding Contact
wx.cloud.callFunction({
  name: 'addContact',
  data: {
    name: this.data.newContactName,
    phone: this.data.newContactPhone,
    email: this.data.newContactEmail,
    address: this.data.newContactAddress
  },
  success: res => {
    console.log('Contact added successfully', res);
    // Update page status
  },
  fail: err => {
    console.error('Failed to add contact', err);
  }
});

// Get contact list
wx.cloud.callFunction({
  name: 'loadContacts',
  success: res => {
    this.setData({
      contacts: res.result  // Update contact list
    });
  },
  fail: err => {
    console.error('Failed to retrieve contacts', err);
  }
});

6. Code Explanation

6.1 Frontend

  1. Structure and Layout:
  • By using the scroll view component to implement a scrolling view of the contact list, the user experience is enhanced
  • Use the wx: for loop to group contacts and display them alphabetically, making it easier for users to search.
  • Using the navigator component to redirect to the detailed information page by clicking on the contact name maintains the interface’s sense of hierarchy and logic.
<view class="navi">
  <view class="navitext">咖喱录</view>
</view>
<scroll-view class="contact" scroll-y="true" scroll-into-view="{{loc}}" style="height:{{screenHeight}}rpx">
  <block wx:for="{{filteredContacts}}" wx:key="letter">
    <view class="group" wx:if="{{item.group.length != 0}}" id="{{item.letter}}">
      <view class="header">{{item.letter}}</view>
      <navigator class="card" wx:for="{{item.group}}" wx:for-item="star" wx:key="*this" url="/pages/card/card?id={{star._id}}">
        <view class="name">{{star.name}}</view>
      </navigator>
    </view>
  </block>
</scroll-view>
  1. Data Processing and Display:
  • Retrieve cloud database instances through wx. cloud. database() and read contact data from the contacts collection.
  • After obtaining the data successfully, call the arrangeContact method to classify and sort the contacts.
  • Record error messages when a failure occurs for easy debugging and troubleshooting in the future.
loadContactsFromDatabase() {
  contactsCollection.field({ name: true, _id: true }).get({
    success: res => {
      let contacts = res.data;
      this.arrangeContact(contacts);
    },
    fail: err => {
      console.error('Failed to retrieve contacts from database:', err);
    }
  });
}
  1. Search Function:
  • Implement search function, update searchTerm instantly when user inputs and call filtering function.
  • In filterContacts, real-time filtering of contacts based on user input enables dynamic search.
  • Maintain data responsiveness and real-time performance to enhance user experience.
onSearchInput: function (e) {
  const searchTerm = e.detail.value.toLowerCase();
  this.setData({ searchTerm: searchTerm });
  this.filterContacts();
},

filterContacts: function () {
  const filteredContacts = this.data.contact.map(group => {
    const filteredGroup = group.group.filter(contact =>
      contact.name.toLowerCase().includes(searchTerm)
    );
    return { letter: group.letter, group: filteredGroup };
  }).filter(group => group.group.length > 0);
  
  this.setData({ filteredContacts: filteredContacts });
}

6.2 Backend

  1. Data Access:
  • Create a reference to the contacts collection for CRUD operations.
  • Make data operations more intuitive, and subsequent retrieval, addition, and deletion of contacts can be done through this collection reference.
const contactsCollection = db.collection('contacts');
  1. Data Query and Processing:
  • Use the. get() method to retrieve contact data from the database and specify to only retrieve the required fields.
  • After successful acquisition, organize the data and process it as needed; Record errors when processing failures for subsequent troubleshooting.
contactsCollection.field({ name: true, _id: true }).get({
  success: res => {
    let contacts = res.data;
    this.arrangeContact(contacts);
  },
  fail: err => {
    console.error('Failed to retrieve contacts from database:', err);
  }
});

7. Personal Journey and Learnings

  1. Frontend Learnings:
    During this project, I deepened my knowledge of WeChat’s Mini Program framework, specifically in structuring and optimizing a user interface (UI) for mobile. I learned to efficiently use .wxml and .wxss files to create intuitive layouts and styles tailored for small screens. Handling interactivity in .js files taught me about binding data and dynamically updating UI elements. I gained experience with scroll-view and conditional rendering for organizing contacts by alphabetical sections, refining my approach to implementing both visually appealing and user-friendly features. I also improved my understanding of front-end performance, learning how to balance visual design and usability.
  2. Backend Learnings and Database Skills:
    On the back end, I worked with WeChat’s cloud functions and databases, which streamlined data storage and retrieval. Through this, I gained hands-on experience with NoSQL databases and learned the importance of data structuring, efficient querying, and indexing to manage user data effectively. Implementing the contact storage in a way that integrates smoothly with the UI taught me about asynchronous operations and error handling. I also tackled issues such as data synchronization and managing updates across different devices, which helped me better understand cloud functions’ role in scalable applications.

8. Conclusion

This project has strengthened my full stack development skills, enabling me to effectively connect front-end and back-end. I have learned the importance of maintainable code, proper data processing, and user centered design. In addition, this experience has given me confidence to undertake more complex projects in the future.

<think> 根据用户的问题,我们需要分析`set_instance_assignment -name IO_STANDARD "3.3V LVCMOS" -to 相关引脚名`这条语句的含义、用途、可能遇到的问题及解决方法。以下是分步解析: ### 1. 语句含义 - **`set_instance_assignment`**: Quartus Prime软件中的Tcl命令,用于为特定实例(如引脚、寄存器等)设置约束。 - **`-name IO_STANDARD`**: 指定约束类型为I/O标准。 - **`"3.3V LVCMOS"`**: 具体的I/O标准值,表示3.3V低压互补金属氧化物半导体电平。 - **`-to 相关引脚名`**: 目标引脚名称(如`clk`、`data[0]`等)。 该语句的作用是将指定引脚的电平标准设置为3.3V LVCMOS。 ### 2. 用途 1. **电气特性匹配**:确保FPGA引脚与外部器件(如传感器、存储器)的电压电平兼容。 2. **信号完整性**:定义驱动能力和摆率,减少信号反射和串扰。 3. **功耗优化**:不同I/O标准对应不同的静态/动态功耗,选择合适标准可降低系统功耗。 4. **时序约束基础**:I/O标准影响输入延迟和输出延迟,是时序分析的依据。 ### 3. 可能遇到的问题及解决方法 #### 问题1:I/O标准与物理电路不匹配 - **现象**:信号传输错误、器件损坏。 - **原因**:FPGA引脚配置为3.3V LVCMOS,但外接器件使用1.8V LVCMOS。 - **解决**: - 核对器件数据手册,确保电平匹配。 - 修改约束:`set_instance_assignment -name IO_STANDARD "1.8V LVCMOS" -to 引脚名`。 #### 问题2:引脚复用冲突 - **现象**:编译报错(如“I/O bank voltage conflict”)。 - **原因**:同一I/O Bank内混合使用不同电压标准的引脚。 - **解决**: - 原则:同一Bank内所有引脚必须使用相同电压。 - 方法:通过Pin Planner查看Bank分区,将不同电压标准的引脚分配到不同Bank。 #### 问题3:驱动能力不足 - **现象**:信号边沿畸变、数据传输误码率高。 - **原因**:默认驱动电流(如4mA)无法满足长距离传输。 - **解决**: - 增加驱动电流约束: ```tcl set_instance_assignment -name CURRENT_STRENGTH_NEW "12MA" -to 引脚名 ``` - 在Pin Planner中调整“Drive Strength”设置。 #### 问题4:未生效或覆盖 - **现象**:约束被忽略,实际电平错误。 - **原因**: - 约束语句位置错误(如写在SDC时序文件中)。 - 优先级冲突(工程设置>实例约束)。 - **解决**: - 将约束写入`.qsf`文件。 - 检查约束优先级:在Assignment Editor中确认是否被覆盖。 ### 4. 验证方法 1. **编译后查看报告**: - 打开“Fitter” → “Resource Section” → “Pin Out File”,确认引脚电平标准。 2. **SignalTap调试**: - 捕获实际信号电平,验证是否符合预期。 3. **硬件测试**: - 用示波器测量引脚电压波形。 ### 示例 以下是为`clk`引脚设置3.3V LVCMOS的完整约束: ```tcl set_instance_assignment -name IO_STANDARD "3.3V LVCMOS" -to clk ``` ### 总结 正确设置I/O标准是FPGA设计的关键步骤,需结合硬件电路和时序需求谨慎配置。遇到问题时,优先检查电平兼容性、Bank分区和驱动能力设置[^1][^3]。 §§相关问题§§ 1. 如何查看Quartus Prime中的I/O Bank电压分区? 2. 不同I/O标准(如LVDS、SSTL)的应用场景有何区别? 3. 当FPGA与多个不同电压器件连接时,如何设计电平转换电路? </think> ### `set_instance_assignment` 语句分析 #### 1. **语句含义** ```tcl set_instance_assignment -name IO_STANDARD "3.3V LVCMOS" -to 相关引脚名 ``` - **`set_instance_assignment`**:Quartus Prime 的 Tcl 约束命令,用于为特定对象(如引脚、寄存器等)分配属性。 - **`-name IO_STANDARD`**:指定约束类型为 I/O 电平标准。 - **`"3.3V LVCMOS"`**:具体的电平标准值(3.3V 低压 CMOS 电平)。 - **`-to 相关引脚名`**:目标引脚名称(如 `clk`, `data[0]` 等)。 **完整含义**:将指定 FPGA 引脚的电气特性配置为 3.3V LVCMOS 标准,确保与外部电路电平兼容。 #### 2. **核心用途** 1. **电平匹配** - 确保 FPGA 引脚电压(3.3V)与外部器件(如传感器、存储器)的 I/O 电压一致,防止电平不兼容导致的信号错误或硬件损坏[^1][^3]。 - 示例:连接 3.3V 的 UART 串口时需配置为 LVCMOS。 2. **信号完整性优化** - 定义引脚的驱动能力(电流强度)、摆率(slew rate),减少信号反射和串扰。 3. **功耗控制** - 不同 I/O 标准对应不同静态/动态功耗,LVCMOS 适用于中低速场景,比 LVDS 等高速标准更节能。 4. **时序约束基础** - I/O 标准影响输入/输出延迟,为后续时序分析(如 `set_input_delay`)提供依据。 #### 3. **常见问题及解决方法** ##### 问题 1:电平不匹配导致信号错误 - **现象**: 外部器件使用 1.8V 电平,但 FPGA 引脚配置为 3.3V LVCMOS,导致逻辑误判或器件损坏。 - **解决**: ```tcl set_instance_assignment -name IO_STANDARD "1.8V LVCMOS" -to 引脚名 ;# 修改为匹配电平 ``` ##### 问题 2:I/O Bank 电压冲突 - **现象**: 编译报错 `I/O bank has incompatible voltage standards`。 - **原因**: 同一 I/O Bank 内的引脚必须使用相同电压(如 Bank 3 所有引脚需统一为 3.3V)[^3]。 - **解决**: - 方法 1:将冲突引脚移到其他电压兼容的 Bank。 - 方法 2:通过 Pin Planner 手动调整 Bank 分配。 ##### 问题 3:驱动能力不足 - **现象**: 信号边沿畸变,长距离传输时数据错误。 - **解决**: 增加驱动电流约束(默认通常为 4mA): ```tcl set_instance_assignment -name CURRENT_STRENGTH_NEW "12MA" -to 引脚名 ;# 提升至 12mA ``` ##### 问题 4:约束未生效 - **现象**: 编译后 I/O 标准仍为默认值。 - **排查**: 1. 检查约束文件(.qsf)是否被工程包含。 2. 确认引脚名拼写与顶层模块端口名一致。 3. 在 Assignment Editor 中手动覆盖优先级更高的约束。 #### 4. **最佳实践** 1. **早期约束** 在布局布线前完成 I/O 约束,避免后续时序不收敛: ```tcl # 在 .qsf 文件中优先声明 set_global_assignment -name TOP_LEVEL_ENTITY "top_module" set_instance_assignment -name IO_STANDARD "3.3V LVCMOS" -to clk ``` 2. **差分信号特殊处理** 若使用 LVDS 等差分标准,需成对约束: ```tcl set_instance_assignment -name IO_STANDARD "LVDS" -to rx_p set_instance_assignment -name IO_STANDARD "LVDS" -to rx_n ;# 互补引脚 ``` 3. **验证方法** - 编译后查看 **Fitter > Resource Section > Pin Out File** 报告,确认电平标准生效。 - 使用 SignalTap 抓取实际信号波形[^4]。 > **关键总结**:此约束是 FPGA 硬件交互的基础,需严格匹配外部电路特性。电平错误可能直接损坏器件,设计时务必核对数据手册的电气参数[^1][^3]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值